如何重新安装Broken npm

问题描述 投票:5回答:2

我刚刚尝试使用npm时安装了节点v9.11.1我一直收到以下错误:

npm WARN npm npm does not support Node.js v9.11.1
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
npm WARN npm You can find the latest version at https://nodejs.org/

我试图做npm i -g npm但它无法更新自己,它只是在上面抛出相同的错误。

当我运行npm -v它说5.5.1似乎最新版本目前5.8.0

我尝试删除文件夹并在node.js安装程序上运行修复功能,但它没有替换模块。

node.js npm install uninstall reinstall
2个回答
8
投票

删除全局NPM文件夹

https://stackoverflow.com/a/5926706/349659

npm list -g

对于Windows,这很可能是:

%AppData%\npm\node_modules

您可以将其粘贴到文件夹的地址栏中,它会将您带到那里。

删除名为npm的文件夹后。

下载NPM的最新版本

https://github.com/npm/cli/releases/latest

抓住zip并将其解压缩到您刚删除npm文件夹的node_modules文件夹中。

将您从zip中提取的文件夹重命名为npm

如果您收到有关文件路径或名称太长的任何警告,请跳过警告。

好运更新

现在你应该能够运行npm i -g npm来更新/重新安装npm而不会发出任何警告。

如果您在Windows中有关于路径或文件名太长的错误,我发现此步骤尤其重要。

您可能会收到以下错误。如果你去删除或移动它列出的文件,你应该能够成功运行npm i -g npm

npm ERR! Refusing to delete C:\Program Files\nodejs\npx.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npx.cmd
npm ERR! Move it away, and try again.

npm ERR! Refusing to delete C:\Program Files\nodejs\npm.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm.cmd
npm ERR! Move it away, and try again.

0
投票

试试这个:

npm install npm@latest -g

更多信息here

© www.soinside.com 2019 - 2024. All rights reserved.