错误无法确定 Node.js 安装目录

Mat*_*eil 7 node.js npm

我尝试通过以下方式安装离子npm install ionic

ionic start myapp blank不起作用,从那时起任何 npm 命令都会告诉我:

$ npm config
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module 'C:\Users\dandonneau.m\devc\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
Could not determine Node.js install directory
Run Code Online (Sandbox Code Playgroud)

Bod*_*dix 6

我遇到了同样的错误,因为我的系统使用的 Node 版本太新。

  • 我有 Windows 7。

  • Windows 7 上最新正式测试的 Node 版本是 13.6.0 (来源)。不过,您也可以尝试运行较新的版本,例如 15.8.0 (source)

  • 当我尝试使用 Node 版本 17.1.0 时,出现了该错误。

解决方案

  1. 我通过将 Node 版本降级到 15.8.0 解决了这个问题(在我的例子中是通过nvm,你可以重新安装)。
  2. 您还可以尝试升级操作系统。