nvm: NVM is not compatible with the npm config "prefix" option warning (OS X)

Split off from https://github.com/creationix/nvm/issues/855 ; see that issue for a similar problem.

This is in OS X El Capitan, 10.11.6 . This error appears on starting a new shell:

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 v5.7.1 --silent` to unset it.

With the usual command in the .bashrc file:

export NVM_DIR="/Users/pingraham/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

Running either or both of the suggested fixes don’t appear to do anything, though.

Note: I foolishly installed some node version globally while trying to fix this, and also foolishly upgraded npm once in an attempt to fix this, but ran into an entirely different npm bug ( https://github.com/npm/npm/issues/13918 , if you’re curious ) before giving up. On the other hand, NVM seems to sorta work anyway…? Maybe?

Here’s some commands & their results:

node -v
v5.7.1

nvm use 5.7.1
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 v5.7.1` to unset it.

Running either or both of the suggested command doesn’t change anything.

Oddly enough, the switch seems to work anyway… maybe…

nvm use 0.10
Now using node v0.10.33 (npm v1.4.28)

node -v
v0.10.33

nvm use 5.7.1
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 v5.7.1` to unset it.

node -v
v5.7.1

(I guess it happened regardless??)

Debugging info:

echo $PREFIX ; echo $NPM_CONFIG_PREFIX

(nothing, just empty lines)

nvm debug
nvm --version: v0.32.0
$SHELL: /bin/bash
$HOME: /Users/pingraham
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
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

(nvm debug, after switching)

nvm current: v0.10.33
which node: $NVM_DIR/v0.10.33/bin/node
which iojs: 
which npm: $NVM_DIR/v0.10.33/bin/npm
npm config get prefix: $NVM_DIR/v0.10.33
npm root -g: $NVM_DIR/v0.10.33/lib/node_modules

nvm ls
       v0.10.33  
         v5.7.1  
->       system  
default -> 5.7.1 (-> v5.7.1)
node -> stable (-> v5.7.1) (default)
stable -> 5.7 (-> v5.7.1) (default)
iojs -> N/A (default)
lts/* -> lts/argon (-> N/A)
lts/argon -> v4.5.0 (-> N/A)

No prefixes set in the environment, either:

$PREFIX: ''
$NPM_CONFIG_PREFIX: ''

It seems wrong to just ignore the error! Any ideas on what I could change? And is it a “Real” error, or just noise, since it seems that at least node -v acknowledges the switches anyway?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 8
  • Comments: 66 (12 by maintainers)

Commits related to this issue

Most upvoted comments

nvm unalias default worked for me! Much appreciated @MwumLi 🍻

The Fix rm $(which npm) if and only if it was installed by a non-nvm node and is taking precedence over nvm’s node.

You can check this by doing the following:

nvm deactivate
ls -la $(which npm)

If it points to something outside of $NVM_DIR it may be causing problems.

The explanation I ran into this today ONLY when starting tmux. I am using oh-my-zsh on a mac however I think the following may benefit anyone.

First, I uninstalled node from brew brew uninstall node Then I debugged a ton and found that the npm being used was a leftover from my brew node installation. npm was located at /usr/local/bin/npm but symlinked to /usr/local/lib/node_modules. Because of this, the default prefix was takining over and set to /usr/local.

So I performed the following to ensure brew’s node was gone:

sudo rm -rf  /usr/local/lib/node_modules
rm /usr/local/bin/npm
brew uninstall --force node
brew prune

No more errors YAY!

In hindsight, I believe all I really needed to do was either rm the npm symlink in /usr/local/bin and perhaps the npm install source at /usr/local/lib/node_modules/bin/npm (not sure of this path).

@peteringraham hm, it’s possible that v5.7.1 is corrupted? could you try nvm uninstall v5.7.1 && nvm install v5.7.1 and see if the issue is fixed?

Wow I’m tired of this issue - seems to affect me randomly on various machines and CI environments. 3 years old and still going strong.

Not sure why it’s marked as fixed? Nothing is fixed… none of the above solutions seem to work for me.

If you’re using any other shell than bash, make sure to configure your tmux that way:

# set default shell to zsh
set -g default-command /bin/zsh
set -g default-shell /bin/zsh

This solved it for me.

@antony you can try the ways:

  1. comment out the code below in your shell file (such as ~/.zshrc):
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
  1. log out your account and log in
  2. uncommnet these code above and source shell file

When I use tmux, the bug apear, so I view code, find the real reason is PATH overlap which result in Determine if the nvm path exists error

How to solve the bug? There’re three way:

  1. simple, but you cann’t set default: nvm unalias default
  2. complex, modify function nvm_change_path:
nvm_change_path() {
  local NVM_NPM_PREFIX
  NVM_NPM_PREFIX="$(npm config --loglevel=warn get prefix)"
  # if there’s no initial path, just return the supplementary path
  if [ -z "${1-}" ]; then
    nvm_echo "${3-}${2-}"
  # if the initial path doesn’t contain an nvm path, prepend the supplementary
  # path
  elif ! (nvm_tree_contains_path "$NVM_DIR" "$NVM_NPM_PREFIX" >/dev/null 2>&1); then
    nvm_echo "${3-}${2-}:${1-}"
  # use sed to replace the existing nvm path with the supplementary path. This
  # preserves the order of the path.
  else
    nvm_echo "${1-}" | command sed \
      -e "s#${NVM_DIR}/[^/]*${2-}[^:]*#${3-}${2-}#g" \
      -e "s#${NVM_DIR}/versions/[^/]*/[^/]*${2-}[^:]*#${3-}${2-}#g"
  fi
}
  1. Hope someone can make a PR, 👏

@ljharb I’m thinking the same thing. Removing the default alias fixed this but shouldn’t there be another way around this?

Update: As a workaround, I removed the default alias and then added the following to my .bashrc file.

nvm use --delete-prefix v8.16.0

That did the trick but then I decided to give the chosen answer here one more shot (which I’m sure I had done in the past) and it actually worked for me.

$ npm config delete prefix
$ npm config set prefix $NVM_DIR/versions/node/v8.16.0 # Where v8.16.0 is the version you want

If this doesn’t work for you then try unsetting default and then adding the --delete-prefix line I included above in your .bashrc or .zshrc file.

I was able to leave the system node on and simply remove the npm install that it came with (might not need the system node anyway so it’s probably going out - it might be that something needed it - cannot remember…)

rm -rf /usr/local/lib/node_modules/npm

That was enough for me.

nvm unalias default worked for me! Much appreciated @MwumLi 🍻

Thanks. This one helped for me.

None of the fixes here seem to have worked for me, and I get this error regardless of which version I’m trying to switch to.

However, if I merely run nvm use a second time, it succeeds. I wonder if that’s why some of these fixes “worked” for other folks here? If I open a new terminal I get the error again the first time I run nvm use, and after that it’s okay.

I tried all but still not work for me. I use where node and found I have a node of global in /usr/local/bin/node. then I use this to delete it

sudo rm -rf /usr/local/lib/node_modules
sudo rm /usr/local/bin/node
cd  /usr/local/bin && ls -l | grep "../lib/node_modules/" | awk '{print $9}'| xargs rm

and then, it work for me!!!

@ljharb why yes 😃 moving source nvm after all of that fixed my problem, thanks! The offending line was pretty obvious in retrospect:

PATH="/usr/local/bin:/usr/local/opt/subversion/libexec:/opt/apache-maven-3.3.9/bin:$PATH"

nvm unalias default worked for me as well, thanks.

I had this problem not when launching Ubuntu (in my WSL 1 env in Win10), but when opening tmux within it. Super annoying, those error messages should be removed since doing the fixes in them didn’t help at all.

@ljharb Thanks! nvm uninstall v5.7.1 && nvm install v5.7.1 worked for me.

It is not fixed! i’m having the same problem for multiple versions of node. tried uninstalling and reinstalling as suggested in some of the comments above. But that did not fix it for me.

Looks like it worked. I guess this was a side-effect of sudo npm install -g when trying to fix unrelated errors earlier.

nvm uninstall 5.7.1
file is not writable: $NVM_DIR/versions/node/v5.7.1/bin/grunt
Cannot uninstall, incorrect permissions on installation folder.
This is usually caused by running `npm install -g` as root. Run the following commands as root to fix the permissions and then try again.

  chown -R pingraham "$NVM_DIR/versions/node/v5.7.1"
  chmod -R u+w "$NVM_DIR/versions/node/v5.7.1"

After running those, uninstalling, and reinstalling, no error message, node -v returns 5.7.1.

I’ll re-open if something surprising happens later, but I think this is mostly fixed.

Note that nvm ls now claims it’s using “5.7.1” rather than “system”, so maybe using the system version of node isn’t really supported? OTOH, this might be too specific & weird a situation to bother having specific commentary on.

Thanks again for your help.

The route that got me to this error was mixing installations of node based packages using nvm and brew. This can get a bit painful as installing the heroku tools or yarn will install their own version of node. I was able to resolve my issues by only ever using nvm. Big YMMV.

Just run into this issue, and here’s what I did to fix it:

  1. remove node: brew uninstall node
  2. install desired version: nvm install 'lts/*'
  3. set the default version: nvm alias default 'lts/*'
  4. delete npm prefix: npm config delete prefix
  5. set prefix to the node version used with nvm: npm config set prefix $NVM_DIR/versions/node/v12.18.1

I go this error because my $HOME contains a slash at the end on macOS 10.14 so my NVM_PATH looked like this /Users/username//.nvm. Changing the NVM_PATH to export NVM_DIR="$HOME.nvm" solved the issue.

EDIT: changing the home location in the macOS user settings is actually the better solution.

@antony you can try the ways:

  1. comment out the code below in your shell file (such as ~/.zshrc):
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
  1. log out your account and log in
  2. uncommnet these code above and source shell file

This worked for me! Thanks!

Doing that will mean your shell starts out without any node version available, please note.

@ljharb if you’re using nvm it should be located under your nvm versions like:

/Users/codyswartz/.nvm/versions/node/v11.12.0/bin/npm

Not something like the following that mine was pointed at:

/usr/local/bin/npm

Yet when I ran which node it was pointing at nvm, so that’s why I was confused where the rouge global nvm came from. It might have been from some ruby gem I installed recently. I treat node installs Ephemerally so reinstalling isn’t much concern for me.

Not sure what installed a global npm for me, but I ran this to have npm uninstall itself

Note: I had to run this twice.

# Run until which npm returns: npm not found
npm un -g npm
which npm

Afterwards I uninstalled my current nvm node version I was on, and then reinstalled it to get a standard npm back and running.

CURRENT_NODE_VERSION="$(nvm version)"
nvm use vSOMETHING_ELSE
nvm uninstall $CURRENT_NODE_VERSION
nvm install $CURRENT_NODE_VERSION

Hope this helps someone…

nvm unalias default

Thanks. Worked for me.

@rifler are you using husky along with commitizen, by chance?

the latest version of husky (and many previous versions) leverages nvm to run your tests in the version of node defined in your .nvmrc. the newest versions, that haven’t hit latest yet, don’t do this anymore (i think because it is assumed that if you are using nvm that you are already running the correct version through other means), so they avoid this problem.

try npm install husky@next -D if this does apply to you and see if it resolves this particular issue.

Good point @ljharb - the better fix was deleting the version entry in ${HOME}/.npmrc. No idea how it got there…

Do you have anything in ~/.bash_profile and/or ~/.bashrc that refers to PATH, nvm, or npm?

I had something like source ~/.nvm/nvm.sh in my ~/.zshrc. Once I removed it, i don’t see the error message.

I came against the same problem. I reinstalled nvm, using zsh custom plugin, then everything went fine 😄
Here, section “As an Oh My ZSH! custom plugin”

@TitanNano’s fix worked fo rme too. Mine was set to export NVM_DIR=~/.nvm which i guess didn’t have a good reference back to the real home

In my case, I just uninstalled nodejs installed by system (sudo apt uninstall nodejs), removed ~/.nvm folder, cleaned up .bashrc and .zshrc from nvm related commands, then installed nvm again.

Pretty simple fix

Navigate to your .nvm folder remove all npm version, since you can just reinstall with nvm easily then run unset npm_prefix_config, then install some arbitrary npm version using nvm, then run nvm use {version you installed}

Boom npm is usable again.

EDIT:

My Mistake the final command you must run is

ln -s $(which node) /usr/local/bin/node

which should put the current node being used in the path.

I fixed this by deleting a ~/.huskyrc file. Not sure how it got there, but I tested my hooks after deleting it and they still work.

nvm unalias default worked for me! Much appreciated @MwumLi 🍻 this is the solution 😃

@ctsstc global npm comes with node, and you should never uninstall it - the only cure is reinstalling node to get it back.

@travi it helps, thank you!

MWumLi’s fix worked for me. Yes, this was highly annoying and time-consuming to fix. I’m happy to report the fix is quite simple.

@jedwards1211 is there any chance you have something in your shell profile files that modifies the PATH after nvm is sourced? If so, a second nvm use would correct the PATH.

(also per https://github.com/creationix/nvm/issues/855#issuecomment-249264066, you don’t have any “prefix” in any .npmrc files, and per https://github.com/creationix/nvm/issues/855#issuecomment-249265561, you don’t have any case-insensitive form of “prefix” in env)

I assume that nvm ls, after the nvm use, has the -> pointing at “v5.7.1”?

Do you have anything in ~/.bash_profile and/or ~/.bashrc that refers to PATH, nvm, or npm?

I’m seeing a few strange things here:

  • nvm use complains about the prefix, but you don’t have any prefix overrides set anywhere
  • when nvm use complains about the prefix, the node version still changes (it should be running nvm deactivate after printing that error)