Switching among Node. 7; we can simply run either nvm use 12.22. 7 or nvm use 16.13. 0 to easily switch into either version we need. Note that since we only have one version that begins with 12, 14, or 16, we can switch versions with a simple nvm use 16 , nvm use 14 , or nvm use 12 command.
Just type nvm alias default v10. 16.3 in your terminal and then type nvm use default . This command will make v10. 16.3 available in any shell you open — you just have to restart your terminal to make sure it works.
From the “View” menu, choose the Terminal option. Type node -v in the Terminal and then press Enter. You should see your Node version in the output. You will see the Node Version in the output.
First, you need to find out the version of your Node Package Manager (npm), by running npm -v command. After checking the version, you can run the command npm install npm@latest -g to install the latest version of Node Package Manager.
In VS Code:
launch.json
fileruntimeVersion
attribute inside configurations as shown belowIn this example, we are assuming 4.8.7 is already installed using nvm:
{
"version": "<some-version>",
"configurations": [
{
"type": "node",
"runtimeVersion": "4.8.7", // If i need to run node 4.8.7
"request": "launch",
"name": "Launch",
"program": "${workspaceFolder}/sample.js"
}
]}
The solution is to set alias default
. In the OS terminal run -
nvm alias default 7.8.0
Open vscode, now running node -v
returns 7.8.0
It seems vscode takes up this (alias default) value and not the node version that is set by nvm use X.X.X
Restart VS code for it to pick up the changes.
Update (12/04/2018) - This solution might not work for everyone. Please see below answers for other solutions.
add runtimeExecutable
to your .vscode/launch.json
like this
{
"type": "node",
"request": "launch",
"name": "App",
"program": "${workspaceRoot}/index.js",
"runtimeExecutable": "${env:HOME}/.nvm/versions/node/v6.9.2/bin/node"
}
I had the same problem of being unable to keep my node version specified trough nvm in my OS X environment not only with VSCode but also with Atom Editor (using the platformio-ide-terminal package for managing the integrated terminal in it). None of the suggestions in the previous answers worked for me, besides me not using the debugger but using gulp and grunt for specific tasks. Apparently nvm does not get along with the integrated terminals or sub shells at least in these editors because when loading them the environment variable $PATH is modified internally and does the following according to a comment by one of the contributors of this package in this issue reported here NVM fails to load within nested shell #1652:
" @charsleysa I know why nvm is throwing this error. In your subshell, somehow the /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin part of your PATH has been moved from the end of the PATH to the start.
- When nvm is then started, it calls nvm_change_path (my contribution changed it to this from nvm_prepend_path), which modifies the nvm-relevant part of the path in place.
- Nvm then checks the current npm prefix by asking npm what it is. Since /usr/local/bin/npm now has precendence, it reports /usr/local/bin.
- Nvm then checks whether the current prefix as reported by npm is in the directory tree of the current nvm node version (at this stage, the installation directory of the node version your default nvm alias resolves to).
- The prefix is not part of that tree, so it deactivates itself (calling nvm_strip_path in the process, which is why there's no nvm-related path in your subshell's PATH), and bails with the error you're getting. macOS's /etc/profile (or /etc/zprofile) calls /usr/libexec/path_helper, which does the PATH switcheroo.
In the parent shell, the PATH doesn't yet have an nvm dir in it, so by the time nvm runs, it prepends its directory to the path. But in the subshell, PATH has been reconfigured by macOS to put any non-system directories at the end and we have the problem."
I was always getting this message when launching any integrated terminal:
nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local"
Run npm config delete prefix
or nvm use --delete-prefix vx.x.x --silent
to unset it.
What I did to solve this in my case was the "workaround" part of that same issue reported which is essentially the following:
And after that no more warnings when I launch any integrated terminal on both editors and I can interact with nvm to switch between any node version easily and without problems at all.
Here it is another alternative just in case this one doesn`t help that much.
Some of the answers provided are correct and upvoted, but somewhat incomplete. This procedure worked for me:
node -v
. You'll get for instance v10.12.0
.nvm use v12.14.0
)Cmd
+ Shift
+ p
and choose Preferences > Open Settings (JSON)
"terminal.integrated.shellArgs.osx": []
to your user configCmd
+ Shift
+ p
and choose Shell Command: Install 'code' command in PATH
code
. This will open VS Code with a new and updated bash
/ zsh
session.node -v
. You'll get v12.14.0
.Bonus: If you always want to get a particular node version on VS Code's terminal, set it as default by opening a terminal window outside VS Code and running:
nvm alias default v12.14.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With