Operating system and version: MacOS High Sierra 10.13
nvm debug output:
nvm --version: v0.33.6
$TERM_PROGRAM: Apple_Terminal
$SHELL: /bin/bash
$HOME: /Users/stonehippo
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)'
uname -a: 'Darwin 17.0.0 Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64 x86_64'
OS version: Mac 10.13 17A405
curl: /usr/bin/curl, curl 7.54.0 (x86_64-apple-darwin17.0) libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0
wget: /usr/local/bin/wget, GNU Wget 1.19.2 built on darwin17.0.0.
git: /usr/local/bin/git, git version 2.14.3
grep: /usr/local/bin/grep, grep (GNU grep) 3.1
awk: /usr/local/bin/awk, GNU Awk 4.2.0, API: 2.0 (GNU MPFR 3.1.6, GNU MP 6.1.2)
sed: /usr/local/bin/sed, sed (GNU sed) 4.4
cut: illegal option -- -
usage: cut -b list [-n] [file ...]
cut -c list [file ...]
cut -f list [-s] [-d delim] [file ...]
cut: /usr/bin/cut,
basename: illegal option -- -
usage: basename string [suffix]
basename [-a] [-s suffix] string [...]
basename: /usr/bin/basename,
sed: -e expression #1, char 9: Unmatched ) or \)
rm: illegal option -- -
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
rm: ,
sed: -e expression #1, char 9: Unmatched ) or \)
mkdir: illegal option -- -
usage: mkdir [-pv] [-m mode] directory ...
mkdir: ,
xargs: illegal option -- -
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
[-L number] [-n number [-x]] [-P maxprocs] [-s size]
[utility [argument ...]]
xargs: /usr/bin/xargs,
nvm current: v8.8.1
which node: $NVM_DIR/versions/node/v8.8.1/bin/node
which iojs:
which npm: $NVM_DIR/versions/node/v8.8.1/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v8.8.1
npm root -g: $NVM_DIR/versions/node/v8.8.1/lib/node_modules
nvm ls output: v6.11.5
-> v8.8.1
default -> 8.8.1 (-> v8.8.1)
node -> stable (-> v8.8.1) (default)
stable -> 8.8 (-> v8.8.1) (default)
iojs -> N/A (default)
lts/* -> lts/boron (-> v6.11.5)
lts/argon -> v4.8.5 (-> N/A)
lts/boron -> v6.11.5
How did you install nvm? (e.g. install script in readme, homebrew): Install script
What steps did you perform?
Installed nvm via the standard script in MacOS terminal, installed node 8.8.1 (default alias was created) and lts/boron, then opened VSCode (with and without extensions), started terminal.
The VS Code terminal displayed the following error at startup:
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 v8.8.1 --silent` to unset it.
This error does not appear in MacOS terminal, only the VS Code terminal. Removing the default alias in .nvm/alias removes the error message at startup (and node continues to function correctly).
The node environment does not appear to get set up correctly as shown in this run of nvm debug from the VS Code terminal when the issue appears:
nvm --version: v0.33.6
$TERM_PROGRAM: vscode
$SHELL: /bin/bash
$HOME: /Users/stonehippo
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)'
uname -a: 'Darwin 17.0.0 Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64 x86_64'
OS version: Mac 10.13 17A405
curl: /usr/bin/curl, curl 7.54.0 (x86_64-apple-darwin17.0) libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0
wget: /usr/local/bin/wget, GNU Wget 1.19.2 built on darwin17.0.0.
git: /usr/local/bin/git, git version 2.14.3
grep: /usr/local/bin/grep, grep (GNU grep) 3.1
awk: /usr/local/bin/awk, GNU Awk 4.2.0, API: 2.0 (GNU MPFR 3.1.6, GNU MP 6.1.2)
sed: /usr/local/bin/sed, sed (GNU sed) 4.4
cut: illegal option -- -
usage: cut -b list [-n] [file ...]
cut -c list [file ...]
cut -f list [-s] [-d delim] [file ...]
cut: /usr/bin/cut,
basename: illegal option -- -
usage: basename string [suffix]
basename [-a] [-s suffix] string [...]
basename: /usr/bin/basename,
rm: illegal option -- -
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
rm: /bin/rm,
mkdir: illegal option -- -
usage: mkdir [-pv] [-m mode] directory ...
mkdir: /bin/mkdir,
xargs: illegal option -- -
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
[-L number] [-n number [-x]] [-P maxprocs] [-s size]
[utility [argument ...]]
xargs: /usr/bin/xargs,
nvm current: none
which node:
which iojs:
which npm: /usr/local/bin/npm
npm config get prefix: env: node: No such file or directory
npm root -g: env: node: No such file or directory
Restoring the default alias triggers the error message. In addition, it is possible to invoke nvm use default and get the environment to work. The issue occurs on at startup.
The error should not occur when the default alias is present, and nvm should load the version assigned to the default alias.
.bashrc, .bash_profile, .zshrc, etc) that modifies the PATH?No
What is pwd in the VSCode terminal? If you cd into that directory in the normal terminal, and run nvm use node, can you replicate the error?
@ljharb The error occurs regardless of the directory. For example, I can get it to happen in my home directory or in a project directory.
Gotcha, and presumably only in VSCode and nowhere else.
In VSCode terminal, what does npm config get prefix return?
@ljharb In my MacOS terminal, it returns /Users/stonehippo/.nvm/versions/node/v8.8.1.
If I try it the VS Code terminal when it first starts, error: env: node: No such file or directory. I can invoke nvm use default at that point, and it's the same as above. So the issue only seems to happen right at the startup of the terminal.
@ljharb Sorry, I think the above was unclear. Once I do nvm use default in the VS Code terminal, the result of npm config get prefix becomes /Users/stonehippo/.nvm/versions/node/v8.8.1, which is what shows up in the MacOS terminal all the time.
I think i see the problem - you don't have a system node installed, but somehow you have a system npm at /usr/local/bin/npm - why is this there (without node)? If you remove it, does everything work?
@ljharb Aha! That's it. It looks like the "system" node wasn't. What is showing up is actually a node installed by brew (as a dependency from another package). I killed that node, but it looks like it left npm and npx behind. Once I killed those, the error went away.
I was able to confirm this on a second system. First, cleaned of the "system" node and npm/npx, confirmed the error was gone, then reinstalled it with brew install node. Error returned. So that was it, for sure. I just tried to install a system node with the official installer, same problem. So it's the system npm getting called first. Any ideas for preventing this, or should I go file this with the VS Code team?
I think this isn't actually an issue with either; it was an issue with your system. Installing node with brew can cause problems; brew uninstall node is supposed to remove npm along with node; if you ran brew install npm separately from node, that's another problem (npm only ever comes with node and should never be installed separately).
Either it's an issue with homebrew (npm should never exist on the system without node), or an issue with VSCode (does it use the same PATH as on your real terminal?) - I'm not really sure which.
@ljharb hmm. I agree that the leftover npm is a brew issue (it should really have gone when node is uninstalled).
Now that I know what to look for, I can see the legit which statements for my system node, and I am getting the error in the VS Code terminal. Remove the system node, no issues. That doesn't seem system specific. I can reproduce this on two systems: it's possible they've both got the same issue, but it doesn't seem to be brew's fault in the end. Maybe it's a pathing issue inside the VS Code terminal, as you suggest. I'll mess around with it and let you know.
Gotcha; in that case it's a VSCode issue, since it's differing from your system terminal. Perhaps there's VSCode configuration that sets the PATH differently, or attempts to locate node/npm?
@ljharb I think it's an issue with VSCode, as well, maybe specific to MacOS High Sierra. I've opened an issue over there, and I'm going to close this one for now. I tried the same setup in an Ubuntu VM, and no issues (obviously no brew, either). If I get a chance, I'll also try to reproduce on a Mac that's never had brew installed.
Thanks for the help.
@ljharb I was able to replicate this issue on a system that never had brew, node, VS Code or nvm on it before. I installed node via the official package, nvm + a node (which got set to default) and VS Code. With this setup, same error as before, so it seems like an interaction between nvm.sh and the VS Code terminal.
I'm reopening this one, as it seems to be related to a known issue with nvm, which is that NVM has trouble when starting up in a nested shell. @charsleysa notes that VS Code appears to do just that in its terminal, as revealed by
echo $SHLVL // returns 2 in VS Code terminal
So this looks like it is very similar to https://github.com/creationix/nvm/issues/1652.
Here's a reference to the VS Code issue comment that points back to NVM:
https://github.com/Microsoft/vscode/issues/37296#issuecomment-341504374
I don't know if removing or uninstalling node via brew is a good idea. Especially because it's a dependency for yarn.
For example:
$ brew uninstall node
Error: Refusing to uninstall /usr/local/Cellar/node/8.9.0
because it is required by yarn 1.3.2, which is currently installed.
You can override this and force removal with:
brew uninstall --ignore-dependencies node
a) you can install yarn via npm, or via non-brew means; b) yarn should be able to use nvm's node without brew installing node.
And you can install Yarn through Homebrew without node:
$ brew install yarn --without-node
To fix it, in addition to delete npm on /usr/local/bin, I also have to delete node file on /usr/local/bin
I had the same issue after installing node using homebrew.
The command brew uninstall node leaves behind /usr/local/bin/npm
a quick rm -rf /usr/loca/bin/npm solved it!
I believe this has been resolved in an update to nvm itself. Please reopen if not.
Actually after removing /usr/loca/bin/npm it solved my prefix issue but I have an app that is spawning a process using node and the command is npm run dev on my terminal it works but from the app it errors out this is the error.
/bin/sh: npm: command not found So I guess the question is how do I point npm from the nvm folder to the /bin/sh?
npm is provided by node; nvm sets up the PATH so that node and npm are available. If your PATH is not set up properly, that implies a few things: that the shell giving the error isn’t sourcing nvm, but also, your app may not be spawning a child process with the correct environment.
I think i see the problem - you don't have a system node installed, but somehow you have a system
npmat/usr/local/bin/npm- why is this there (without node)? If you remove it, does everything work?
I found that incomplete uninstall of homebrew's nodes will cause this problem, in order to find them all you could try ls -l /usr/local/bin/ | grep node .
Most helpful comment
I think i see the problem - you don't have a system node installed, but somehow you have a system
npmat/usr/local/bin/npm- why is this there (without node)? If you remove it, does everything work?