nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
MIT License
79.62k stars 7.97k forks source link

VSCode Terminal causes 'nvm is not compatible with the npm config "prefix" option' warning #1690

Closed MikeTheCanuck closed 6 years ago

MikeTheCanuck commented 6 years ago

Hi folks, in my latest nvm configuration I am now seeing the nvm is not compatible with the npm config "prefix" option error when opening the VS Code Terminal. (Opening a bash session using Terminal.app doesn't show any warnings or errors.)

I skimmed #855 and didn't find an obvious solution - that issue made this error sound like an unfortunate bug in nvm.sh so I was hoping there'd be a permanent solution that didn't require us to run another command every time a shell is opened.

nvm --version: v0.33.5
$TERM_PROGRAM: vscode
$SHELL: /bin/bash
$HOME: /Users/mike
$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.3.0 Darwin Kernel Version 17.3.0: Thu Nov 9 18:09:22 PST 2017; root:xnu-4570.31.3~1/RELEASE_X86_64 x86_64'
OS version: Mac 10.13.2 17C88
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: not found
git: /usr/local/bin/git, git version 2.15.0
grep: /usr/bin/grep, grep (BSD grep) 2.5.1-FreeBSD
awk: /usr/bin/awk, awk version 20070501
sed: illegal option -- -
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
sed: /usr/bin/sed,
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: system
which node: /usr/local/bin/node
which iojs:
which npm: /usr/local/bin/npm
npm config get prefix: /usr/local
npm root -g: /usr/local/lib/node_modules

         v6.5.0
        v6.11.2
        v6.11.4
         v8.9.1
->       system
default -> lts/* (-> v8.9.1)
node -> stable (-> v8.9.1) (default)
stable -> 8.9 (-> v8.9.1) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> v8.9.1)
lts/argon -> v4.8.6 (-> N/A)
lts/boron -> v6.12.0 (-> N/A)
lts/carbon -> v8.9.1

MikeTheCanuck commented 6 years ago

D'oh! Sorry, I didn't spot #1647 and #1652 until after filing this and continuing to dig around the interwebs. Feel free to close this as a duplicate of those.

ljharb commented 6 years ago

Sounds good :-)

danieldbird commented 6 years ago

I fixed this temporarily by adding nvm use node to the end of my .bash_profile after the nvm path export. export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion nvm use node c

ljharb commented 6 years ago

@danieldbird you shouldn't need that if you do nvm alias default node once in the terminal.

danieldbird commented 6 years ago

@ljharb only to get around the nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local" Runnpm config delete prefixornvm use --delete-prefix v9.6.1 --silentto unset it. error in VSCode and Atom. It works fine in the native terminal, or iTerm, and throws no error message. This seems to be happening because no version of node is being used when first opening the integrated terminal in VSCode or Atom.

Edit: Even after running nvm alias default node

ljharb commented 6 years ago

@danieldbird can either VSCode or Atom be made to use a login shell?

danieldbird commented 6 years ago

@ljharb I saw another discussion you were a part of that helped me. It appears I have fixed the issue. What I did was ensure the following were uninstalled brew uninstall node, brew uninstall npm, brew uninstall nvm, then I ensured the hidden home directories were removed .npm, .nvm, then i used the nvm curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash install command. And then I installed node using the OS installer. All is working fine now in both VSCode, Atom, and native terminals, Terminal and iTerm. Thanks.

xintaoLi commented 6 years ago

i have the same problem , nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local/Cellar/node@6/6.12.3" Run npm config delete prefix or nvm use --delete-prefix v8.9.4 --silent to unset it.

it worked after i delete the folder: rm -rf /usr/local/Cellar/node@6

ThibaudCrespin commented 6 years ago

Fix here : https://github.com/Microsoft/vscode-docs/blob/master/docs/editor/integrated-terminal.md#why-is-nvm-complaining-about-a-prefix-option-when-the-integrated-terminal-is-launched

ogryzek commented 6 years ago

That fix doesn't seem to resolve it for me.

As a workaround, I've redirected the output to /dev/null and called nvm use node in my ~/.bashrc

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  2>/dev/null
$(nvm use node) 2>/dev/null
latel commented 6 years ago

@ThibaudCrespin this solved my problem. cheers

cikichen commented 6 years ago

@ThibaudCrespin Great! Best!

HanZhaoYoung commented 6 years ago

@ThibaudCrespin it works well! thanks!

webkong commented 6 years ago

i have the same problem, rm -R /usr/local/lib/node_modules/npm rm -R /usr/local/bin/npm /usr/local/lib/node_modules/npm/bin/npm-cli.js this resolve my problem, because I install node use brew install node brefore. you need uninstall node and npm when use nvm.

mulhoon commented 6 years ago

Tried lots of these things, but the only thing that worked for me was installing node/npm via the installer from nodejs.org then adding export PATH=$PATH:/usr/local/git/bin in my ~/.bash_profile Hope this helps someone.

RavenHursT commented 6 years ago

brew uninstall --ignore-dependencies node (igonore-deps because I had yarn installed) worked for me. What @webkong said was accurate. At the end of the day, if you have nvm installed then there's no need for a "global" node/npm install. Remove them (however you installed them determines how that gets done) and you're good.

Guang1234567 commented 5 years ago

1) brew uninstall node

2) https://github.com/Microsoft/vscode-docs/blob/master/docs/editor/integrated-terminal.md#why-is-nvm-complaining-about-a-prefix-option-when-the-integrated-terminal-is-launched

3) reinstall nvm

`curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash`
greentornado commented 5 years ago

Thanks @Guang1234567, it helps

Guang1234567 commented 5 years ago

@greentornado

glad works for you, haha.

J0R1SK commented 5 years ago

@ThibaudCrespin Finally the solution that works for me. Thank you very much!

homerjam commented 3 years ago
  1. $ brew uninstall --ignore-dependencies node

Microsoft/vscode-docs@master/docs/editor/integrated-terminal.md#why-is-nvm-complaining-about-a-prefix-option-when-the-integrated-terminal-is-launched

  1. reinstall nvm $ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.37.2/install.sh | bash

This was the solution for me, thanks!

derekck commented 3 years ago

Just had this issue myself. Got around it by switching to the right node version for my project in the terminal (in my case nvm use 10), THEN opening VS Code from that terminal window. From there when I open a debugging window in VS Code, it has the right node version set.

surz-p commented 3 months ago

This bug annoyed me for weeks, if not months, even in 2024. Finally, I was able to get rid of it (with some help from this thread).

In my case, the following sequence worked:

And just like that, opening the Javascript Debug Terminal on VSCode no longer annoyed me with the nvm is not compatible with the npm config "prefix" option bug! 😃

IT WAS INSANELY SATISFYING! 😮‍💨

fantasy525 commented 1 month ago

i have the same problem, rm -R /usr/local/lib/node_modules/npm rm -R /usr/local/bin/npm /usr/local/lib/node_modules/npm/bin/npm-cli.js this resolve my problem, because I install node use brew install node brefore. you need uninstall node and npm when use nvm.

thank you,this solved my problem,I used homebew to install node before