Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
peteringraham opened this issue Sep 26, 2016 · 37 comments

Comments

Projects
None yet
@peteringraham
Copy link

commented Sep 26, 2016

Split off from #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 ( npm/npm#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?

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Sep 26, 2016

(also per #855 (comment), you don't have any "prefix" in any .npmrc files, and per #855 (comment), 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)
@peteringraham

This comment has been minimized.

Copy link
Author

commented Sep 26, 2016

I don't believe so, as far as PATH /nvm / npm references of note. My ~/.bash_profile:

source ~/.bashrc

if [ -f ~/.git-completion.bash ]; then
  . ~/.git-completion.bash
fi

The source of the bashrc seems like it shouldn't really be necessary to me, but .bashrc doesn't run if I don't include it.

The only thing in .bashrc of potential interest is pretty bog-standard:

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

eval "$(grunt --completion=bash)"

For nvm ls: Not that one version. If I use 5.7.1, it points to "system" instead (which is hopefully harmless, since node -v indicates system IS 5.7.1 ). npm -v says it is 3.6.0. If I use some other version (e.g. v.0.10.36), then it points to that, yes (and npm -v gives 2.20 ).

(after terminal start, or nvm use 5.7.1)

nvm ls
       v0.10.33  
       v0.10.36  
         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)

Thanks for looking into this!

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Sep 26, 2016

@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?

@peteringraham

This comment has been minimized.

Copy link
Author

commented Sep 27, 2016

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.

drewr added a commit to drewr/dotfiles that referenced this issue Feb 25, 2017

drewr added a commit to drewr/dotfiles that referenced this issue Feb 25, 2017

drewr added a commit to drewr/dotfiles that referenced this issue Feb 25, 2017

@elimcjah

This comment has been minimized.

Copy link

commented Aug 31, 2017

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

@jedwards1211

This comment has been minimized.

Copy link

commented Dec 12, 2017

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.

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Dec 12, 2017

@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.

@jedwards1211

This comment has been minimized.

Copy link

commented Dec 12, 2017

@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"
@antony

This comment has been minimized.

Copy link

commented Jan 9, 2018

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.

@MwumLi

This comment has been minimized.

Copy link

commented Feb 28, 2018

@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
@PascalPrecht

This comment has been minimized.

Copy link

commented Mar 5, 2018

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.

@akrois

This comment has been minimized.

Copy link

commented Mar 14, 2018

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.

@MwumLi

This comment has been minimized.

Copy link

commented Mar 15, 2018

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, 👏
@prachikhadke

This comment has been minimized.

Copy link

commented Apr 26, 2018

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.

@yochem

This comment has been minimized.

Copy link

commented May 4, 2018

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

@Strongbyte-FP

This comment has been minimized.

Copy link

commented May 8, 2018

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).

@rifler

This comment has been minimized.

Copy link

commented May 10, 2018

@MwumLi nvm_change_path:2: command not found: npm

@MwumLi

This comment has been minimized.

Copy link

commented May 12, 2018

@rifler Do you install npm? Your result show npm not be installed.

@rifler

This comment has been minimized.

Copy link

commented May 12, 2018

globally not, only via nvm

@MwumLi

This comment has been minimized.

Copy link

commented May 15, 2018

@rifler Here, first say sorry, my code has little bug.
npm config --loglevel=warn get prefix get current node path, but the above code not include the condition which npm has been not installed, so, you should add the judge: if npm not installed, this means node not be installed , you can use nvm_echo "${3-}${2-}:${1-}" directly.
I read nvm code a long time ago , so there may be some mistakes. 🤭

@r1b

This comment has been minimized.

Copy link

commented May 25, 2018

@Strongbyte-FP This was exactly my problem - thank you!

@DavideDaniel

This comment has been minimized.

Copy link

commented Jun 8, 2018

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.

@xwchris

This comment has been minimized.

Copy link

commented Jul 11, 2018

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!!!

@rifler

This comment has been minimized.

Copy link

commented Jul 20, 2018

I realised, that this behaviour connected with commitizen
when I simply run git commit -am "msg" - all hooks run fine
when I run git-cz - I get

nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/Users/rifler/.nvm/versions/node/v10.6.0"
Run `unset npm_config_prefix` to unset it.
husky > can't find npm in PATH, skipping precommit script in package.json
nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/Users/rifler/.nvm/versions/node/v10.6.0"
@travi

This comment has been minimized.

Copy link

commented Jul 20, 2018

@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.

@rifler

This comment has been minimized.

Copy link

commented Jul 20, 2018

@travi it helps, thank you!

@icehongssii

This comment was marked as disruptive content.

Copy link

commented Aug 7, 2018

@ljharb Thank you Father. Spent 1 day to fix this.

@giedriusr

This comment has been minimized.

Copy link

commented Oct 24, 2018

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

Thanks. This one helped for me.

@codeshifu

This comment has been minimized.

Copy link

commented Nov 11, 2018

nvm unalias default

Thanks. Worked for me.

@ramanandapanda

This comment has been minimized.

Copy link

commented Nov 13, 2018

I just close the terminal by right clicking the icon below and clicking on force quit and reopened it. This worked for me.

dleve123 added a commit to dleve123/dotfiles that referenced this issue Dec 3, 2018

Tell tmux about Homebrew-managed bash
Before this commit, I was getting nvm loading errors along the lines of:

```
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.
```

whenever opening a new tmux window or split.

By following the spirit of the advice [in this GH comment][0], these
loading errors went away.

[0]:
nvm-sh/nvm#1245 (comment)
@szm1002

This comment has been minimized.

Copy link

commented Mar 21, 2019

@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!

@ctsstc

This comment has been minimized.

Copy link

commented Mar 22, 2019

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...

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Mar 22, 2019

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

@ctsstc

This comment has been minimized.

Copy link

commented Mar 22, 2019

@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.

@brapastor

This comment has been minimized.

Copy link

commented Apr 4, 2019

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

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Apr 4, 2019

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

@bradydowling

This comment has been minimized.

Copy link

commented May 1, 2019

@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 me .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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.