Skip to content

Instantly share code, notes, and snippets.

@stormwild
Last active June 11, 2022 03:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stormwild/8ff4328c6f8b92ba4d4b4a0908c324f6 to your computer and use it in GitHub Desktop.
Save stormwild/8ff4328c6f8b92ba4d4b4a0908c324f6 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

@seanyujc
Copy link

seanyujc commented Jan 8, 2021

for linux:
"terminal.integrated.shellArgs.linux": [ "-i" ]

@dpschen
Copy link

dpschen commented Mar 16, 2021

I had the same problem. In my case the error came from homebrew and could be solved via this (actually also for other programs):
https://docs.brew.sh/FAQ#my-mac-apps-dont-find-usrlocalbin-utilities

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