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

Conversation

knqu
Copy link
Contributor

@knqu knqu commented Mar 18, 2025

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • The changes are appropriately documented (if applicable).
  • The changes have sufficient test coverage (if applicable).
  • The testsuite passes successfully on my local machine (if applicable).

Summarize your changes:

Fixes #3554

This PR introduces an early Node.js version check in the electron-forge.ts CLI entry point. This prevents syntax errors caused by unsupported Node versions and provides a clear error message to the user.

@knqu knqu requested a review from a team as a code owner March 18, 2025 16:02
Comment on lines 10 to 15
if (!semver.satisfies(process.versions.node, packageJSON.engines.node)) {
console.error(`You are running Node.js version ${process.versions.node}, but Electron Forge requires Node.js ${packageJSON.engines.node}.`);
process.exit(1);
}

import './util/terminate';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular reason for this to come before ./util/terminate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to have the version check before the other imports so that execution is immediately halted if an incompatible Node version is detected. The performance gain is probably negligible, but I thought it would better indicate the Node.js version as a critical prerequisite. However, I can also move all of the imports to the top of the file if you prefer the imports to be grouped.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think I would prefer that. I took a quick look at ./util/terminate and there isn't anything that seems like it would throw a Node version-related error and having all imports be at the top makes the code clearer.

@knqu
Copy link
Contributor Author

knqu commented Mar 18, 2025

Please take a look at these revisions and let me know what you think. I moved the imports for ./util/terminate and ./util/check-system up to the top of the file. However, I have the import for listr2 below the version check because it throws SyntaxError: Unexpected token '??=' when the Node.js version is below 16.

Copy link
Member

@erickzhao erickzhao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, I have the import for listr2 below the version check because it throws SyntaxError: Unexpected token '??=' when the Node.js version is below 16.

Haha I realize now that we actually had a copy of this code running through the Listr2 interface, which is useless if Listr2 is failing to load in the first place.

Can you clean up this bit of code as well as part of the PR? I think just removing the Node check from there would suffice.

title: 'Checking node version',
task: async (_, task) => {
const nodeVersion = await checkNodeVersion();
task.title = `Found node@${nodeVersion}`;
},

@knqu
Copy link
Contributor Author

knqu commented Mar 18, 2025

Good catch, let me know how this looks.

@erickzhao erickzhao self-requested a review March 18, 2025 20:33
@erickzhao
Copy link
Member

Pushed up 2eacbaf as a nit but otherwise good to go.

@erickzhao erickzhao added this pull request to the merge queue Mar 19, 2025
Merged via the queue into electron:main with commit de1ab07 Mar 19, 2025
6 of 11 checks passed
@knqu knqu deleted the unsupported-node-version-error branch March 20, 2025 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix(cli): add descriptive error for node version mismatch
2 participants