Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): add descriptive error for unsupported node version #3894

Merged
merged 4 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/api/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"debug": "^4.3.1",
"fs-extra": "^10.0.0",
"listr2": "^7.0.2",
"log-symbols": "^4.0.0",
"semver": "^7.2.1"
},
"engines": {
Expand Down
18 changes: 15 additions & 3 deletions packages/api/cli/src/electron-forge.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
#!/usr/bin/env node
// This file requires a shebang above. If it is missing, this is an error.

import chalk from 'chalk';
import { program } from 'commander';
import { Listr } from 'listr2';

import './util/terminate';
import logSymbols from 'log-symbols';
import semver from 'semver';

import packageJSON from '../package.json';
import './util/terminate';

import { checkSystem, SystemCheckContext } from './util/check-system';

if (!semver.satisfies(process.versions.node, packageJSON.engines.node)) {
console.error(
logSymbols.error,
`You are running Node.js version ${chalk.red(process.versions.node)}, but Electron Forge requires Node.js ${chalk.red(packageJSON.engines.node)}. \n`
);
process.exit(1);
}

/* eslint-disable-next-line import/order -- Listr2 import contains JS syntax that fails as early as Node 14 */
import { Listr } from 'listr2';

program
.version(packageJSON.version, '-V, --version', 'Output the current version.')
.helpOption('-h, --help', 'Output usage information.')
Expand Down
18 changes: 0 additions & 18 deletions packages/api/cli/src/util/check-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ async function getGitVersion(): Promise<string | null> {
});
}

async function checkNodeVersion() {
const { engines } = await fs.readJson(path.resolve(__dirname, '..', '..', 'package.json'));
const versionSatisfied = semver.satisfies(process.versions.node, engines.node);

if (!versionSatisfied) {
throw new Error(`You are running Node.js version ${process.versions.node}, but Electron Forge requires Node.js ${engines.node}.`);
}

return process.versions.node;
}

/**
* Packaging an app with Electron Forge requires `node_modules` to be on disk.
* With `pnpm`, this can be done in a few different ways.
Expand Down Expand Up @@ -130,13 +119,6 @@ export async function checkSystem(callerTask: ForgeListrTask<SystemCheckContext>
}
},
},
{
title: 'Checking node version',
task: async (_, task) => {
const nodeVersion = await checkNodeVersion();
task.title = `Found node@${nodeVersion}`;
},
},
{
title: 'Checking package manager version',
task: async (_, task) => {
Expand Down