node.js 尝试更新后无法再使用 npm 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22102396/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:56:40  来源:igfitidea点击:

Can no longer use npm command after trying to update

node.jsyeoman

提问by user2483724

I was trying to install yeoman but it threw an error regarding self signed certificates.

我试图安装 yeoman,但它抛出了一个关于自签名证书的错误。

I looked this up and I found out I had to upgrade node.

我查了一下,发现我必须升级节点。

Upgrading node however threw this: (forgot to use sudo with it...)

然而升级节点抛出了这个:(忘记使用 sudo ......)

npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/npm'
npm ERR! error rolling back  [email protected] { [Error: EACCES, unlink '/usr/local/lib/node_modules/npm']

After this I couldn't use npm anymore. It couldn't be found:

在此之后,我不能再使用 npm 了。找不到:

/usr/local/bin/npm: No such file or directory

Trying to reinstall with brew:

尝试使用 brew 重新安装:

It appears you already have npm installed at /usr/local/lib/node_modules/npm

Tells me to npm uninstall but I can't use npm anymore.

告诉我 npm uninstall 但我不能再使用 npm 了。

The error message is more detailed but I think the part about "unlinking" is the main thing. How do I go about linking it back up and also why was such a weird error thrown?

错误消息更详细,但我认为关于“取消链接”的部分是主要的。我该如何将它重新链接起来,以及为什么会抛出如此奇怪的错误?

EDIT: also ran npm config set ca ""before trying to update node.

编辑:也在npm config set ca ""尝试更新节点之前运行。

采纳答案by user2483724

Found some links with similar errors and all with different solutions:

找到了一些具有类似错误的链接,并且都具有不同的解决方案:

https://github.com/npm/npm/issues/4099

https://github.com/npm/npm/issues/4099

Error: The 'brew link' step did not complete successfully

错误:“酿造链接”步骤未成功完成

How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

如何完全卸载 Node.js,并从头开始重新安装 (Mac OS X)

The answer for the third one helped most I think, specifically:

我认为第三个答案最有帮助,特别是:

go to /usr/local/lib and delete any node and node_modules

转到 /usr/local/lib 并删除任何节点和 node_modules

回答by bahek2462774

I installed using brew after: brew install node

我之后使用 brew 安装: brew install node

sudo brew postinstall node

回答by learn2reid

sudo brew postinstall command works for me. This issue is caused if you try to update a core NPM package without using the sudo command

sudo brew postinstall 命令对我有用。如果您尝试在不使用 sudo 命令的情况下更新核心 NPM 包,则会导致此问题