nvm: nvm prefix error appears in VS Code terminal only when default alias is present
-
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.
- What happened?
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.
- What did you expect to happen?
The error should not occur when the default alias is present, and nvm should load the version assigned to the default alias.
- Is there anything in any of your profile files (
.bashrc
,.bash_profile
,.zshrc
, etc) that modifies thePATH
?
No
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 23 (8 by maintainers)
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?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!And you can install Yarn through Homebrew 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
@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 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
.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.
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 ranbrew 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 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.
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:
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
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