Skip to content

Instantly share code, notes, and snippets.

@jonlabelle
Forked from stormwild/vscode-terminal-nvm.md
Created June 11, 2022 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonlabelle/b714a694db8597b92e2980467e79ef4d to your computer and use it in GitHub Desktop.
Save jonlabelle/b714a694db8597b92e2980467e79ef4d to your computer and use it in GitHub Desktop.
Visual Studio Code NVM Node Integrated Terminal Issue

Visual Studio Code NVM Node Issue

NVM

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

Visual Studio Code

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:

Shell arguments

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

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment