如何重新安装损坏的npm [英] How to Reinstall Broken npm
问题描述
当我尝试使用npm时,我刚刚安装了节点v9.11.1
,我不断收到以下错误:
I just installed node v9.11.1
when I try to use npm I keep getting the following error:
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
,但是它无法更新自身,只是不断在上面抛出相同的错误.
I tried to do npm i -g npm
but it couldn't update itself, it just kept throwing the same error above.
当我运行npm -v
时,它说5.5.1
,似乎最新版本是5.8.0
.
When I run npm -v
it says 5.5.1
it seems the latest version is currently 5.8.0
.
我尝试删除该文件夹并在node.js安装程序上运行修复功能,但是它没有替换模块.
I tried deleting the folder and running the repair function on the node.js installer, but it didn't replace the module.
推荐答案
删除全局NPM文件夹
https://stackoverflow.com/a/5926706/349659
npm list -g
对于Windows,最有可能是:
For Windows this will most likely be:
%AppData%\npm\node_modules
您可以将其粘贴到文件夹的地址栏中,它将带您到那里.
You can paste that into a folder's address bar and it will take you there.
在其中删除名为npm
的文件夹.
Once there delete the folder named npm
.
https://github.com/npm/cli/releases/latest
抓取zip并将其解压缩到您刚刚从中删除npm文件夹的node_modules
文件夹中.
Grab the zip and unzip it to your node_modules
folder that you just deleted the npm folder from.
将您从zip提取的文件夹重命名为npm
Rename the folder you extracted from the zip to npm
如果您收到有关文件路径或名称太长的任何警告,请跳过警告.
If you get any warnings about the file path or name being too long skip the warnings.
现在,您应该能够运行npm i -g npm
来更新/重新安装npm,而不会出现任何警告.
Now you should be able to run npm i -g npm
to update/reinstall npm without any warnings.
如果您在Windows中由于路径或文件名过长而出现错误,我认为此步骤特别重要.
I find this step especially important if you had errors in Windows about the path or file name being too long.
您可能会遇到以下错误.如果确实要删除并移动列出的文件,则应该可以成功运行npm i -g npm
.
You may get the following errors. If you do go and delete or move the files it has listed and you should be able to run npm i -g npm
successfully.
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.
这篇关于如何重新安装损坏的npm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!