Given that nvm
is installed on Mac OS X High Sierra or Mojave using the install script
~/.bash_profile
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
On Mac Visual Studio Code can be launched from the launcher or dock or from the terminal by running code <path>
In Visual Studio Code settings.json:
You can pass arguments to the shell when it is launched.
For example, to enable running bash as a login shell (which runs .bash_profile), pass in the -l argument (with double quotes):
~/Library/Application Support/Code/User/settings.json
{
"terminal.integrated.shellArgs.osx": ["-l"]
}
prompt> echo $0 -bash # "-" is the first character. Therefore, this is a login shell. prompt> echo $0 bash # "-" is NOT the first character. This is NOT a login shell.
Launching Visual Studio Code from the terminal using code
and then opening a terminal allows nvm to load.
But it seems we have to call nvm use v10.15.3
to use node specified by nvm
.
When launching Terminal within Visual Studio Code run the following example:
nvm use v10.15.3
This will ensure that the node and npm version being run in that particular terminal session will use the node specified by nvm. You will have to do this for every terminal you launch.
nvm uses a shell function (instead of an environment variable) to configure the path to the node.js.
This is not supported in VS Code on macOS.
The workaround is to use the runtimeVersion attribute:
{ "type": "node", "request": "launch", "name": "Launch Program", "program": "${workspaceFolder}/test.js", "runtimeVersion": "4.6" }
...research in progress
- Install & Update script
- nvm is not compatible with the npm config “prefix” option:
- Integrated terminal does not see Node from NVM #48576
- NVM is not compatible with the npm config "prefix" option warning (OS X) #1245
- What does this command do? “exec bash -l”
- Configuration
- Shell arguments
- Difference between Login Shell and Non-Login Shell?