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 v6.10.1 --silent` to unset it.

Created on 13 Oct 2018  ·  30Comments  ·  Source: nvm-sh/nvm

  • Operating system and version:
    macOS high sierra version 10.13.1
  • nvm debug output:

nvm --version: v0.33.11
$TERM_PROGRAM: Apple_Terminal
$SHELL: /bin/bash
$SHLVL: 1
$HOME: /Users/Tahshara
$NVM_DIR: '$HOME/.nvm'
$PATH: /usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$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.2.0 Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3

  • nvm ls output:

        v6.10.0
        v6.10.1
        v8.11.3
        v10.8.0
->       system
default -> 6.10.1 (-> v6.10.1)
node -> stable (-> v10.8.0) (default)
stable -> 10.8 (-> v10.8.0) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.4 (-> N/A)
lts/carbon -> v8.12.0 (-> N/A)

  • How did you install nvm? (e.g. install script in readme, Homebrew):
    I don't remember. I've followed a lot of online documentation.
  • What steps did you perform?
    idk
  • What happened?
    idk
  • What did you expect to happen?
    expected for the nvm install to be successful
  • Is there anything in any of your profile files (.bashrc, .bash_profile, .zshrc, etc) that modifies the PATH?
needs followup

Most helpful comment

Had the same issue, turns out i had separate npm installed system wide. Removing it helped.

All 30 comments

Do you have a "prefix" line in ~/.npmrc? If so, delete it and try again.

I still get nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local"
I ran the following commands:
npm i remove-prefix
MacBook-Pro-4:~ Tahshara$ nvm debug
nvm --version: v0.33.11
$TERM_PROGRAM: Apple_Terminal
$SHELL: /bin/bash
$SHLVL: 1
$HOME: /Users/Tahshara
$NVM_DIR: '$HOME/.nvm'
$PATH: /usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$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.2.0 Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/

npm i remove-prefix won't do anything. You have to edit the ~/.npmrc file and delete any line starting with prefix=.

I don't know how to access the file

vi ~/.npmrc? use whatever command-line editor you prefer.

none of the lines start with prefix
MacBook-Pro-4:~ Tahshara$ vi ~/.npmrc?

~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"~/.npmrc?" [New File]

ok - what does npm config get prefix print out?

Had the same issue, turns out i had separate npm installed system wide. Removing it helped.

Removing the prefix= from my ~/.npmrc seems to have fixed it for me. 🎉

See here: https://github.com/creationix/nvm/issues/1923#issuecomment-437603289

Closing for now; @boocheet, if you're still having issues, I'm happy to reopen.

@ljharb Why does the NPM prefix need to be inside $NVM_DIR?

https://github.com/creationix/nvm/blob/17586b971a750dcc8019aa59169bbfa360374714/nvm.sh#L2174-L2189

Maybe it's a typo and you actually wanted to assert $NVM_DIR is inside the NPM prefix?

-    if ! (nvm_tree_contains_path "$NVM_DIR" "$NVM_NPM_PREFIX" >/dev/null 2>&1); then 
+    if ! (nvm_tree_contains_path "$NVM_NPM_PREFIX" "$NVM_DIR" >/dev/null 2>&1); then 

Or you forgot to include a dirname?

-    if ! (nvm_tree_contains_path "$NVM_DIR" "$NVM_NPM_PREFIX" >/dev/null 2>&1); then 
+    if ! (nvm_tree_contains_path "$(dirname $NVM_DIR)" "$NVM_NPM_PREFIX" >/dev/null 2>&1); then 

IDK, I have no idea what this assertion is for.


edit: I'm using the first diff. If anyone else hits this, here you go.

@aleclarson if pnpm requires the prefix to be set, then pnpm isn’t compatible with nvm. npm root -g must be inside the nvm-controlled node version dir for nvm to work properly.

@ljharb Huh? Why would npm root -g need to be in ~/.nvm to work correctly? And is it npm prefix -g or npm root -g? The code uses npm prefix -g and you're saying npm root -g.

Assuming $NVM_DIR points to ~/.nvm, what should my npm prefix -g or npm root -g be for NVM to work as expected?

The prefix determines the global root, they’re all linked.

nvm needs to be able to switch the global root as it switches the node version. Moving the prefix causes lots of subtle bugs.

So NVM edits the location of my global node_modules when I change Node versions? For what purpose?

Because global modules must be reinstalled and recompiled separately for each node version - so each node version has its own global root.

@ljharb Why can't NVM set the NPM prefix itself? What is the correct NPM prefix if $NVM_DIR equals ~/.nvm?

The npm prefix is set by npmrc, or an environment variable, or npm has its own default. nvm can’t ensure that users don’t override that beyond the nvm use call.

If no prefix is set, then the “prefix” is the same as the default npm root -g - inside the node install dir inside NVM_DIR.

Wow really sorry. Didn't take this comment seriously enough. Ugh..

Unfortunately pnpm breaks with established conventions, and doesn’t work well with the wider ecosystem :-/ its a shame if that means nvm can’t work with it.

It had nothing to do with PNPM in the end. 😆 It was /usr/local/bin/npm causing the fuss. (not sure how it got there)

Should NVM use readlink "$(which npm)" to know if NVM is linked correctly? And then give a really useful error message. 😉

@ljharb I did not look into this issue yet but if something needs to be fixed on pnpm side, we will definitely work on it.

@zkochan thankfully the above comment means that pnpm is fine :-D which I’m glad to hear.

@aleclarson I’d be happy to accept a PR that gives a better error message in a posix-compliant way :-D

Sorry, I can't set aside time to dig into Bash code any more than I have. Since I've figured out this issue, I have to decline. 😢

We had issues with this setup in Mac OSX with node installed with homebrew. Uninstalling it from brew and using only the nvm version solved our issue.
brew uninstall node

In addition to uninstalling node installed via brew as per above, I had to remove the node_modules folder from my brew lib directory, which had globally installed npm. \o/

I couldn't get anything here to work, so I "solved" this issue for myself by adding unset PREFIX to .bashrc before nvm does its initial check. 😂

unset PREFIX
export NVM_DIR="$HOME/.config/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

@Bestulo while this is a workaround, it has the desired effect - if it’s unset, it can’t alter how node or npm works, and thus nvm won’t break. It’s be ideal to figure out what’s setting it tho.

Was this page helpful?
0 / 5 - 0 ratings