首页 > 解决方案 > 无法将 npm 从 6.14.8 更新到 7.3;删除 npm.cmd、npx.cmd 和 npm 会导致更多错误

问题描述

我一直在尝试使用npm install -g npmGit Bash 中的命令全局更新我的 npm,以使其与 Angular 11 和 Node.js 版本 15.5.0 保持同步。我收到以下错误:

npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npm.cmd
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! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

我从中删除了文件nodejs并尝试再次安装,但收到另一个关于npx.cmd. 我删除了该文件,尝试安装,并收到有关 npm 文件的错误。

npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npx.cmd
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! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npm
npm ERR! Refusing to delete C:\Program Files\nodejs\npm: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

删除它们并尝试npm再次安装后,Git Bash 不再找到 npm。安装永远不会开始。

bash: /c/Program Files/nodejs/npm: No such file or directory

我试图从我的漫游文件夹中删除 npm 文件AppData,但收到以下错误:

npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path C:\Users\Yoga 2 Mitchell\AppData\Roaming\npm
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, lstat 'C:\Users\Yoga 2 Mitchell\AppData\Roaming\npm'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

我还在不同的时间尝试了以下方法:

到目前为止没有任何效果。我在上面列表中尝试的第二种方法能够将其更新到 6.14.10,但这种尝试返回的错误似乎会影响 Angular。为了安全起见,我将所有内容恢复到原始状态。请让我知道我是否可以澄清有关我的问题的任何其他内容。

标签: node.jsangulargitnpmnpm-install

解决方案


我就收到的错误与另一位开发人员联系。建议使用以下方法,它可以解决 LTS 的问题:如何从 Windows 中完全删除 node.js

LTS 版本允许我更新到 npm 的 6.14.11,但是当我尝试这种方法安装 Current 版本时,它仍然是 6.14.11。希望这种方法可以帮助遇到类似错误的其他人。


推荐阅读