aizkhaj
aizkhaj

Reputation: 145

VS Code terminal fails to use npm version from nvm

I'm using nvm on my Terminal and successfully installed node 10.2.1, which also installed npm 6.1.0. However, when I go to my VS Code editor, it gives me warnings in the integrated terminal for:

npm WARN npm npm does not support Node.js v10.2.1
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4,6, 7, 8, 9.

Turns out, it is actually using npm 5.5.1 (npm -v).

I check to see what's up with that and tried to dig further and eventually used: which npm on both integrated terminal and Mac's CLI.

Mac's Terminal shows: /Users/Aiz/.nvm/versions/node/v10.2.1/bin/npm

VS Code's Terminal shows: /usr/local/bin/npm. Which is interesting, because if you do which node in this terminal, it results in the appropriate /Users/Aiz/.nvm/versions/node/v10.2.1/bin/node.

I'm not sure how to get my VS Code terminal to point to the appropriate npm install through nvm. Not sure if it helps, but I checked npm get prefix and npm -g bin to find /Users/Aiz/.nvm/versions/node/v10.2.1. The only difference I'm finding is where each terminal is using npm from.

Upvotes: 2

Views: 8117

Answers (3)

squirtgun
squirtgun

Reputation: 709

The fix for me on Ubuntu:

A.) sudo apt-get remove nodejs npm

B.) Removed lines in my .bashrc that added the npm package directory to the path.

C.) Restart VS Code.

I doubt step A is necessary. But B and C certainly are.

Upvotes: 0

Paul Bartlett
Paul Bartlett

Reputation: 831

Another solution is to implement this. https://medium.com/@kinduff/automatic-version-switch-for-nvm-ff9e00ae67f3

Basically, nvm will check for a .nvmrc and switch or default each time you go to a new directory in shell.

It does have a dependency on zsh.

Upvotes: 0

aizkhaj
aizkhaj

Reputation: 145

I ended up looking through VS Code issues on GitHub and came across something relevant to NVM and node issues. It fixed my issue since the underlying cause was the same.

Essentially what happened is that I had a global install of node before that I removed prior to using NVM but hadn't removed my global install of npm. This was causing conflicts in VS Code's terminal (not Mac's terminal). In order to fix this, you essentially have to find the symlink for which npm and remove the node_modules and npm associated recursively.

Here's the link you'll need: https://github.com/Microsoft/vscode-docs/blob/master/docs/editor/integrated-terminal.md#why-is-nvm-complaining-about-a-prefix-option-when-the-integrated-terminal-is-launched.

Don't forget to restart your editor after.

Upvotes: 3

Related Questions