node.js nvm 与 npm 配置“前缀”选项不兼容:
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34718528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nvm is not compatible with the npm config "prefix" option:
提问by Dmitri Zaitsev
I am trying to run another NodeJS version with nvmbut getting this error:
我正在尝试运行另一个 NodeJS 版本,nvm但收到此错误:
$ 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).
我故意设置了前缀以避免sudo npm(参见https://docs.npmjs.com/getting-started/fixing-npm-permissions)。
Is there any way I can use nvmwithout losing my prefix for globally installed packages?
有什么方法可以在nvm不丢失全局安装包的前缀的情况下使用吗?
回答by Mick
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.
nvm 与 npm config "prefix" 选项不兼容:当前设置为 "/usr/local" 运行 "npm config delete prefix" 或 "nvm use --delete-prefix v6.11.1 --silent" 以取消设置。
Credits to @gabfiocchi on Github - "You need to overwrite nvm prefix"
归功于 Github 上的@gabfiocchi - “您需要覆盖 nvm 前缀”
回答by S.M.Mousavi
I had the same problem and executing npm config delete prefixdid not help me.
我遇到了同样的问题,执行npm config delete prefix对我没有帮助。
But this did:
但这确实:
After installing nvm using brew, create ~/.nvmdirectory:$ mkdir ~/.nvm
使用 brew 安装 nvm 后,创建~/.nvm目录:$ mkdir ~/.nvm
and add following lines into ~/.bash_profile:
并将以下几行添加到~/.bash_profile:
export NVM_DIR=~/.nvm
. $(brew --prefix nvm)/nvm.sh
(Check that you have no other nvm related command in any ~/.bashrcor ~/.profileor ~/.bash_profile)
(检查您在任何~/.bashrc或~/.profile或中没有其他与 nvm 相关的命令~/.bash_profile)
Open a new terminal and this time it should not print any warning message.
Check that nvm is working by executing nvm --versioncommand.
After that, install/reinstall NodeJS using nvm install node && nvm alias default node.
打开一个新终端,这次它不应该打印任何警告消息。
通过执行nvm --version命令检查 nvm 是否正常工作。
之后,使用nvm install node && nvm alias default node.
More Info
更多信息
I installed nvmusing homebrewand after that I got this notification:
我安装了nvm使用homebrew,之后我收到了这个通知:
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 ~/.nvmAdd the following to
~/.bash_profileor your desired shell configuration file:export NVM_DIR=~/.nvm . $(brew --prefix nvm)/nvm.shYou can set
$NVM_DIRto any location, but leaving it unchanged from/usr/local/Cellar/nvm/0.31.0will destroy any nvm-installed Node installations upon upgrade/reinstall.
请注意上游要求我们通过 Homebrew 明确管理 nvm 不受他们支持,您应该在报告之前根据标准 nvm install 方法检查任何问题。
如果 NVM 的工作目录不存在,您应该创建它:
mkdir ~/.nvm将以下内容添加到
~/.bash_profile您想要的 shell 配置文件中:export NVM_DIR=~/.nvm . $(brew --prefix nvm)/nvm.sh您可以设置
$NVM_DIR为任何位置,但保持不变/usr/local/Cellar/nvm/0.31.0将在升级/重新安装时破坏任何 nvm 安装的节点安装。
Ignoring it brought me to this error message:
忽略它使我看到此错误消息:
nvmis not compatible with thenpm config"prefix" option: currently set to"/usr/local/Cellar/nvm/0.31.0/versions/node/v5.7.1"
Runnvm use --delete-prefix v5.7.1 --silentto unset it.
nvm与npm config“前缀”选项不兼容:当前设置为"/usr/local/Cellar/nvm/0.31.0/versions/node/v5.7.1"
运行nvm use --delete-prefix v5.7.1 --silent以取消设置。
I followed an earlier guide (from homebrew/nvm) and after that I found that I needed to reinstall NodeJS. So I did:
我遵循了早期的指南(来自homebrew/nvm),之后我发现我需要重新安装 NodeJS。所以我做了:
nvm install node && nvm alias default node
and it was fixed.
它被修复了。
Update:Using brew to install NVM causes slow startup of the Terminal. You can follow this instructionto resolve it.
更新:使用 brew 安装 NVM 会导致终端启动缓慢。您可以按照此说明来解决它。
回答by Healer
This may be a conflict with your local installation of Node (if you had it installed via another way than NVM in the past). You should delete this instance of node:
这可能与您本地安装的 Node 冲突(如果您以前通过 NVM 以外的其他方式安装它)。您应该删除此节点实例:
- remove node_modules
sudo rm -rf /usr/local/lib/node_modules - remove node
sudo rm /usr/local/bin/node - remove node link
cd /usr/local/bin && ls -l | grep "../lib/node_modules/" | awk '{print $9}'| xargs rm
- 删除 node_modules
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
After you cant install nvm
无法安装 nvm 后
回答by André Avelar
This error can occur when your NVM installation folder pathhas a Symbolic Link.
当您的NVM 安装文件夹路径具有Symbolic Link时,可能会发生此错误。
Explanation
解释
The default installation path of NVM is: $HOME/.nvmbut your home folder could be a symbolic link for another drive, like my case.
NVM 的默认安装路径是:$HOME/.nvm但是您的主文件夹可能是另一个驱动器的符号链接,就像我的情况一样。
Example, my home folder is a Symbolic Link to aother drive:
例如,我的主文件夹是到另一个驱动器的符号链接:
/home/myuser -> /bigdrive/myuser
/home/myuser -> /bigdrive/myuser
This cause the prefix problem.
这会导致前缀问题。
Solution
解决方案
On your startup script (.bashrc or .zshrc or other), change the NVM folder to the direct path.
在您的启动脚本(.bashrc 或 .zshrc 或其他)上,将 NVM 文件夹更改为直接路径。
Ex: NVM_DIR="/bigdrive/myuser/.nvm".
例如:NVM_DIR="/bigdrive/myuser/.nvm"。
.bashrc
.bashrc
export NVM_DIR="/bigdrive/myuser/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
回答by Lane Rettig
I ran into this while using node installed via nvm, with nvminstalled via homebrew. I solved it by running brew uninstall nvm, rm -rf $NVM_DIR, then reinstalling nvm using the official install scriptand reinstalling the node version I needed.
我在使用通过安装的节点时遇到了这个问题nvm,nvm通过自制软件安装。我通过运行brew uninstall nvm,解决了它rm -rf $NVM_DIR,然后使用官方安装脚本重新安装 nvm并重新安装我需要的节点版本。
Note: I also had $NVM_DIRmounted and symlinked. I moved it back into my homedir.
注意:我也有$NVM_DIR安装和符号链接。我把它移回我的家目录。
回答by James May
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:
如果您将主目录安装在某处,这可能是问题所在,因为 nvm 无法使用符号链接正常工作。因为我不在乎我的 $NVM_DIR 在哪里,所以我运行它并且一切正常:
$ mv ~/.nvm /tmp/
$ export NVM_DIR="/tmp/.nvm"
$ nvm use --delete-prefix v6.9.1
回答by Panayiotis Georgiou
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
对于那些尝试从 brew 中删除 nvm 的人
it may not be enough to just brew uninstall nvm
仅仅 brew uninstall nvm 可能还不够
if you see npm prefix is still /usr/local, run this command
如果您看到 npm 前缀仍然是 /usr/local,请运行此命令
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
回答by Matthias Schobner
I have the same error message but other solution. The autogenerated path during curl (install.sh) does not match. Check this with:
我有相同的错误消息,但有其他解决方案。curl (install.sh) 期间自动生成的路径不匹配。检查这个:
echo $NVM_DIR
In my case: /var/www//.nvm. Show in your auto generated bash file and change it and replace it: (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc)
就我而言:/var/www//.nvm。在自动生成的 bash 文件中显示并更改并替换它:(~/.bash_profile、~/.zshrc、~/.profile 或 ~/.bashrc)
replace
代替
export NVM_DIR="$HOME/.nvm"
with (e.g.)
与(例如)
export NVM_DIR="$HOME.nvm"
回答by Vadorequest
I followed https://stackoverflow.com/a/47861348/2391795answer but it didn't work out well.
我按照https://stackoverflow.com/a/47861348/2391795回答但效果不佳。
$ npm config delete prefix
$ npm config set prefix $NVM_DIR/versions/node/v6.11.1
After running the recommended commands my nvm didn't work anymore, running nvm usewould display the proper node version being used, but running node -vwould show another. It wasn't possible to change node's version anymore.
运行推荐的命令后,我的 nvm 不再工作,运行nvm use会显示正在使用的正确节点版本,但运行node -v会显示另一个。无法再更改节点的版本。
I uninstalled and reinstalled nvm entirely to fix it. I followed https://github.com/creationix/nvm#manual-uninstallby running
我完全卸载并重新安装了 nvm 以修复它。我通过运行关注https://github.com/creationix/nvm#manual-uninstall
$ rm -rf "$NVM_DIR"
Then edited my .zshrcto remove the lines related to nvm, which in my case were
然后编辑 my.zshrc以删除与 nvm 相关的行,在我的情况下是
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"
Then started a new shell (so that nvm isn't loaded in this new shell) and ran https://github.com/creationix/nvm#install-script
然后启动一个新的 shell(这样 nvm 不会加载到这个新的 shell 中)并运行https://github.com/creationix/nvm#install-script
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
Which added nvm the lines I previously had removed in my .zshrc.
其中添加了 nvm 我之前在我的.zshrc.
Then I was able to use nvm as I used to. I guess that's an odd case were things went wrong and forced me to reinstall everything, doesn't look like most people go through this due to this issue.
然后我就可以像以前一样使用 nvm 了。我想这是一个奇怪的情况,因为出现问题并迫使我重新安装所有东西,看起来大多数人不会因为这个问题而经历这个。
回答by Paul Han
Let me describe my situation.
让我描述一下我的情况。
First, check the current config
首先,检查当前配置
$ nvm use --delete-prefix v10.7.0
$ npm config list
Then, I found the error config in output:
然后,我在输出中发现了错误配置:
; project config /mnt/c/Users/paul/.npmrc
prefix = "/mnt/c/Users/paul/C:\Program Files\nodejs"
So, I deleted the C:\\Program Files\\nodejsin /mnt/c/Users/paul/.npmrc.
所以,我删除了C:\\Program Files\\nodejs/mnt/c/Users/paul/.npmrc 中的。

