Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM not using NVM node version

I'm trying to run scripts specified in a package.json (npm run {scriptName}) using node version 18, I have switched to version 18 using nvm but have run the script and it is running on node v12.

I have tried to delete node from all possible locations I can think of but am still having this problem.

nvm ls produces:

       v14.21.3
->     v18.14.2
default -> 18.14.2 (-> v18.14.2)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v18.14.2) (default)
stable -> 18.14 (-> v18.14.2) (default)
lts/* -> lts/hydrogen (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3
lts/gallium -> v16.19.1 (-> N/A)
lts/hydrogen -> v18.15.0 (-> N/A)

But when I add this code block to any of my scripts I get stdout v12.3.1

const { execSync } = require('child_process');
const stdout = execSync('node --version');
console.log('stdout ', stdout.toString());

which node gives me: ~/.nvm/versions/node/v18.14.2/bin/node

npm version = 6.14.18 nvm version = 0.39.3

Any suggestions on how I can track down where this node v12.3.1 is installed, or another option for getting around this problem?

I've tried cleaning up all installed node version from brew install

I've even tried uninstall nvm and run which node after cleaning up previous installs and it wasn't able to find node anymore.

for the record if I do the following and then run my script it seems to successfully use node v14

nvm install 14 
nvm use 14
like image 287
vijayagurdeep Avatar asked Feb 03 '26 17:02

vijayagurdeep


1 Answers

FYI was able to find out that I had installed npm installed node (globally) at some point after using this debug statement console.log(process.argv)

I removed the installation and I'm now able to successfully use node 16 & 18

like image 53
vijayagurdeep Avatar answered Feb 05 '26 06:02

vijayagurdeep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!