node.js - 错误 : Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' when trying to run npm

标签 node.js npm cmd window

我正在尝试在 Windows 环境中从 cmd 运行 npm install。出现以下错误:

internal/modules/cjs/loader.js:905
  throw err;
  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

\node_modules\npm\bin\在文件路径中重复是有原因的吗? 我已将环境变量设置为:

C:\Program Files\nodejs\node_modules\npm\bin

和:

C:\Program Files\nodejs\

是否有解决此问题的解决方案,以便我可以运行 npm 命令?

最佳答案

复制名为 npm 的目录从您安装的 Node 路径(在我的例子中,npm 目录在 C:\Program Files\nodejs\node_modules 中可用)。

导航到 C:\Users\%USERNAME%\AppData\Roaming\npm\node_modules并将复制的 npm 目录粘贴到那里。

这应该有效。

关于node.js - 错误 : Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' when trying to run npm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69541725/

相关文章:

java - 无法编译和执行java程序

windows - 在Golang中运行Windows命令

node.js - 如何从mapReduce mongoose 中的键获取大约值?

node.js - nodeJS/GitlabCI : How to serve decentralized productive application

node.js - JS 文件更改后出现奇怪的 Ionic CLI 错误

node.js - Laravel Elastic Beanstalk,无法安装运行 npm?

git - Angular 2 组件可以外部化吗?

windows - 我是否将图标设置为使用 mklink cmd 命令的快捷方式

java - 在 nodejs 中获取 socket.io 选项的查询

node.js - Grunt-contrib-watch 看不到新文件