You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React应用安装遇node:internal/modules/cjs/loader:1146错误,npm命令失效求助

解决npm无法找到package.json导致命令全部失效的问题

错误信息

node:internal/modules/cjs/loader:1146
  throw err;
  ^

Error: Cannot find module '../../package.json'
Require stack:
- C:\Users\adity\AppData\Roaming\npm\node_modules\npm\lib\es6\validate-engines.js
- C:\Users\adity\AppData\Roaming\npm\node_modules\npm\lib\cli.js
- C:\Users\adity\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
    at Module._load (node:internal/modules/cjs/loader:984:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (C:\Users\adity\AppData\Roaming\npm\node_modules\npm\lib\es6\validate-engines.js:8:49)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at Module.require (node:internal/modules/cjs/loader:1231:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\adity\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\es6\\validate-engines.js',        
    'C:\\Users\\adity\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\cli.js',
    'C:\\Users\\adity\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js'
  ]
}

Node.js v20.12.1

解决步骤

  • 彻底删除npm全局目录:找到路径C:\Users\adity\AppData\Roaming\npm\node_modules\npm,删除整个npm文件夹;同时删除同目录下的npm.cmd、npx.cmd等脚本文件。
  • 清除npm缓存:手动删除缓存目录C:\Users\adity\AppData\Roaming\npm-cache。
  • 重装/修复Node.js:卸载现有Node.js,下载对应LTS版本安装包,运行时选择「修复」或重新安装,确保安装路径无中文、特殊字符。
  • 验证修复:重启命令提示符,执行node -v、npm -v确认版本输出正常,再测试npm list -g等基础命令。
  • 检查环境变量:确保系统PATH包含Node.js安装目录(如C:\Program Files\nodejs\)和npm全局目录(C:\Users\adity\AppData\Roaming\npm),无重复或错误路径。

内容的提问来源于stack exchange,提问作者Aditya Sanwal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 13:58:01