如何重新安装损坏的 npm [英] How to Reinstall Broken npm

查看:136
本文介绍了如何重新安装损坏的 npm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了 node v9.11.1 当我尝试使用 npm 时,我不断收到以下错误:

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% pm ode_modules

%AppData% pm ode_modules

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

You can paste that into a folder's address bar and it will take you there.

删除名为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
odejs
px.cmd: is outside C:Program Files
odejs
ode_modules
pm and not a link
npm ERR! File exists: C:Program Files
odejs
px.cmd
npm ERR! Move it away, and try again.

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

这篇关于如何重新安装损坏的 npm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆