nvm is not compatible with the npm config “prefix” option:

匿名 (未验证) 提交于 2019-12-03 02:44:02

问题:

I am trying to run another NodeJS version with nvm but getting this error:

$ nvm use v4.2.4  nvm is not compatible with the npm config "prefix" option:     currently set to "/Users/z/.npm-global" Run `npm config delete prefix` or `nvm use --delete-prefix v4.2.4` to unset it. 

I have my prefix set on purpose to avoid sudo npm (see https://docs.npmjs.com/getting-started/fixing-npm-permissions).

Is there any way I can use nvm without losing my prefix for globally installed packages?

回答1:

Simply Delete and Reset the prefix

$ npm config delete prefix  $ npm config set prefix $NVM_DIR/versions/node/v6.11.1 

Note: Change the version number with the one indicated in the error message.

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.11.1 --silent" to unset it.


Credits to @gabfiocchi on Github - "You need to overwrite nvm prefix"



回答2:

I had the same problem and executing npm config delete prefix did not help me.

But this did:

After installing nvm using brew, add following lines into ~/.bash_profile:

export NVM_DIR=~/.nvm . $(brew --prefix nvm)/nvm.sh 

(Check that you have no other nvm related command in any ~/.bashrc or ~/.profile or ~/.bash_profile)

Open a new terminal and this time it should not print any warning message.
Check that nvm is working by executing nvm --version command.
After that, install/reinstall NodeJS using nvm install node && nvm alias default node.

More Info

I installed nvm using homebrew and after that I got this notification:

Please note that upstream has asked us to make explicit managing nvm via Homebrew is unsupported by them and you should check any problems against the standard nvm install method prior to reporting.

You should create NVM's working directory if it doesn't exist:

 mkdir ~/.nvm 

Add the following to ~/.bash_profile or your desired shell configuration file:

 export NVM_DIR=~/.nvm  . $(brew --prefix nvm)/nvm.sh 

You can set $NVM_DIR to any location, but leaving it unchanged from /usr/local/Cellar/nvm/0.31.0 will destroy any nvm-installed Node installations upon upgrade/reinstall.

Ignoring it brought me to this error message:

nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local/Cellar/nvm/0.31.0/versions/node/v5.7.1"
Run nvm use --delete-prefix v5.7.1 --silent to unset it.

I followed an earlier guide (from homebrew/nvm) and after that I found that I needed to reinstall NodeJS. So I did:

nvm install node && nvm alias default node 

and it was fixed.



回答3:

I ran into this while using node installed via nvm, with nvm installed via homebrew. I solved it by running brew uninstall nvm, rm -rf $NVM_DIR, then reinstalling nvm using the official install script and reinstalling the node version I needed.

Note: I also had $NVM_DIR mounted and symlinked. I moved it back into my homedir.



回答4:

It might be the problem if you have your home directory mounted somewhere, due nvm does not work properly with symlinks. Because I don't care where is my $NVM_DIR located I run this and all works fine:

$ mv ~/.nvm /tmp/ $ export NVM_DIR="/tmp/.nvm" $ nvm use --delete-prefix v6.9.1 


回答5:

I was looking for a solution for the nvm prefix problem a found this question(before finding the solution). Here is my shell "dialog". I hope, it can be usefull for somebody. I was able to set to prefix with the help of this post: https://github.com/npm/npm/issues/6592

When I tried npm config delete prefix or nvm use --delete-prefix before using npm --prefix="" set prefix "", I got only: npm ERR! not ok code 0

Note that you will have to repeat the same procedure with every node version, the prefix is set back to (in my case) /usr/local after installation.

    $ nvm install 0.10     ######################################################################## 100.0%     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 v0.10.44` to unset it.     $ npm --prefix="" set prefix ""     $ nvm use 0.10.44     nvm is not compatible with the npm config "prefix" option: currently set to "/home/john"     Run `npm config delete prefix` or `nvm use --delete-prefix v0.10.44` to unset it.     $ nvm use --delete-prefix v0.10.44     Now using node v0.10.44 (npm v1.3.10)     $ nvm ls     v0.10.44              v4.4.3     ->       system     default -> 4.4.3 (-> v4.4.3)     node -> stable (-> v4.4.3) (default)     stable -> 4.4 (-> v4.4.3) (default)     iojs -> N/A (default)     $ npm config get prefix     /usr/local 


回答6:

I had this issue after moving my home folder to a new drive on linux. It was fixed by removing .nvm folder and reinstalling nvm



回答7:

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



回答8:

Just resolved the issue. I symlinked $HOME/.nvm to $DEV_ZONE/env/node/nvm directory. I was facing same issue. I replaced NVM_DIR in $HOME/.zshrc as follows

export NVM_DIR="$DEV_ZONE/env/node/nvm" 

BTW, please install NVM using curl or wget command not by using brew. For more please check the comment in this issue on Github: 855#issuecomment-146115434



回答9:

I had the same problem and it was really annoying each time with the terminal. I run the command to the terminal and it was fixed

For those try to remove nvm from brew

it may not be enough to just brew uninstall nvm

if you see npm prefix is still /usr/local, run this command

sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}



回答10:

Note:
to remove, delete, or uninstall nvm - just remove the $NVM_DIR folder (usually ~/.nvm)
you can try :
rm -rf ~/.nvm



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!