fix: binaries installed in invalid path in Node.js 20 #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In Node.js 20, the behavior of the
process.exit()
function has changed.As a result, npm 7.19.0 or later does not set the correct exit code on error.
See: npm/cli#6399
Therefore, the
child_process.exec()
function will not return an error.This causes binaries to be installed in the wrong path. For example, in the case of go-task, it will be installed in a path such as:
This is the filepath. A multi-line string filepath like this is used.
See: go-task/task#1190
This happens when npm 91 is installed with Node.js 20.
However, the same problem may occur if the
npm bin
command fails with other errors (for example, if Corepack does not allow npm to run).This bug was fixed in npm 9.6.7, but not all users are running the latest version of npm.
In particular, in the environment of users using yarn or pnpm, npm will remain at the old version built into Node.js and will not be updated to the new one.
So the
getInstallationPath()
function also needs to work around this bug.This pull request modifies the
getInstallationPath()
function to avoid this npm bug.Footnotes
The
Unknown command: "bin"
error occurs because thenpm bin
command has been removed from npm 9. ↩