NPM is unexpectedly using an older version of Node

Viewed 17

When I run node -v on my Linux system, I get v16.7.0 as expected given the installed binaries on my PATH, but when my package.json has a scripts element including node -v which is invoked, it prints v9.11.2. Why is that?

(The issue was discovered because it also seems to be actually using the older version, which omits features used by a script I want to run, but -v is the minimal example.)

When I run which/whereis node/npm I get the same result, the expected directory where the binaries are located, which is on my PATH. In looking through other directories on my PATH, I do not see any node/npm executables.

echo "$NODE_PATH" with or without quotes prints a blank line.

I don't see any answers in a $HOME/.npmrc file.

Where is it getting Node v9 from, and how can I fix that so that calling node from within an npm script invokes a more modern version?

1 Answers

The user's global node_modules/.bin folder gets inserted in before the system path, so if node is installed there, it'll be used first. Using the npm uninstall -g node command doesn't necessarily remove it, so you might have to do so manually.

This location can be found out by using the whereis node command as part of an npm script, instead of the node -v step.

Related