-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
[BUG] exit codes not being set properly in node v20 #6399
Comments
npm audit
always exits with 0
The same happens when running workspace scripts: I have made a reproduction repository: https://github.com/darthmaim/node-exit-code-test It only fails on node 20 This probably breaks all CI jobs when using worskpaces and node 20, so maybe this should be higher priority? |
Hi - thanks for looking into this. We're using workspaces, npm 9.6.6 and node 20.1.0 and this is currently breaking our CI jobs |
This should be related to this changes on node side nodejs/node#48027
Lines 220 to 223 in 829503b
process.exitCode set earlier
cli/lib/commands/run-script.js Lines 200 to 222 in 09b58e4
|
@MichaelBitard the previous comment shows the root cause here. v20 subtly changed how exitCode setting works. The |
Ok thanks, from what I see I should rely on it. If I change line 134: Lines 130 to 140 in 829503b
to This seems ok to you? |
|
I think you mean |
oh, if it’s ok to sometimes have zero then your original suggestion is what’s wanted, i was just matching the current semantics, |
Yes I think that's it, if everything works well, then exitHandler is called and process.exitCode is |
Previously, our CI on Node.js 20 was failing silently (e.g. the bug fixed by #1591 did make mocha exit with a non-zero exit code, but not our CI). This is being caused by an incompatibility between npm@8.x and Node.js 20 (which could reasonably be argued to be a Node.js bug, the same one that the PR mentioned above accounts for). Upgrading to npm@9.x should fix this because it includes a fix in npm as well (npm/cli#6399).
Previously, our CI on Node.js 20 was failing silently (e.g. the bug fixed by #1591 did make mocha exit with a non-zero exit code, but not our CI). This is being caused by an incompatibility between npm@8.x and Node.js 20 (which could reasonably be argued to be a Node.js bug, the same one that the PR mentioned above accounts for). Upgrading to npm@9.x should fix this because it includes a fix in npm as well (npm/cli#6399).
Hey guys, as of node |
This is no longer an issue in |
I created a Gist to help test your particular version of NPM. It also protects you from harm if an error is found by adding a small syntax error to the top of your package.json file to render it useless for running https://gist.github.com/happycollision/445c5e3ff6fb6c6eaa1161a441bb7553 |
I'm experiencing this in v20.5.1+ and v22.5.1. Only by reverting back to 18.20.4 did the exit codes start working correctly again. |
I've been experiencing the same problem in my CI builds (they'd always pass with broken tests/checks). Reverting back to 18.20.4 (latest LTS) solved the issue. My setup is basically this:
"test:main": "vitest run",
"test:ci": "npm run test:main", In node 20.10.0, the following command will always return an exit code npm run test:ci -w projects/my-project While in the same version this would return the exit code from npm run test:main -w projects/my-project (btw you can check the exit code of any command with Somehow, calling the Switching the node version to 18.20.4 makes this command |
@damianmr we had a very similar issue where updating the node version would lead to missing non-zero exit code only when being called indirectly - so like your It turned out that we had
This behavior only occured when updating from node 18 to 20 (with the corresponding npm versions), so it looked like the newer npm version was the culprit, when it actually was only partly at fault for suddenly using the local npm version for these multi-step scripts. Maybe you have the same issue? We ended up "fixing" this by just adding |
Thank you for the details, I'll have to investigate if I have |
You're a hero @tiborpilz ! It turns out semantic-release has npm as a dependency, and their older version was causing issues with the exit codes. Adding |
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
Running
npm audit
(seemingly) always exists with a 0 exit code, even if a vulnerability is found (with a severity higher than configured by theaudit-level
).In contrast,
npm@8.15.0
(node@18.7.0
) exits with a 1 if a vulnerability is found (with a severity higher than configured by theaudit-level
).Expected Behavior
Per the Exit Code section:
Steps To Reproduce
npm audit
echo $?
0
being printedEnvironment
The text was updated successfully, but these errors were encountered: