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

重建package-lock.json时遇npm ERR! Cannot convert undefined or null错误求助

解决npm重建package-lock.json时出现“Cannot convert undefined or null to object”错误

现有项目的package-lock.json因不明原因被删除,尝试通过npm i --package-lock-only或直接执行npm install重建该文件时,触发以下错误:

npm ERR! Cannot convert undefined or null to object

具体调用栈日志如下:

2843 verbose stack TypeError: Cannot convert undefined or null to object
2843 verbose stack     at Function.keys (<anonymous>)
2843 verbose stack     at module.exports (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-pick-manifest\lib\index.js:213:22)
2843 verbose stack     at RegistryFetcher.manifest (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\registry.js:119:22)
2843 verbose stack     at async Promise.all (index 10)
2843 verbose stack     at async [buildDepStep] (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1044:5)
2843 verbose stack     at async Arborist.buildIdealTree (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:207:7)
2843 verbose stack     at async Arborist.reify (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:159:5)
2843 verbose stack     at async Install.exec (C:\Program Files\nodejs\node_modules\npm\lib\commands\install.js:147:5)
2843 verbose stack     at async module.exports (C:\Program Files\nodejs\node_modules\npm\lib\cli.js:89:5)

$ node --version
v18.16.0

$ npm --version
9.6.5

解决步骤

  • 清理npm缓存:执行npm cache clean --force
  • 删除本地依赖文件夹:Windows系统执行rd /s /q node_modules,Linux/macOS执行rm -rf node_modules
  • 检查package.json文件:确认所有依赖的版本号格式正确,无空值或无效版本定义
  • 升级npm至最新稳定版:执行npm install -g npm@latest
  • 重新执行npm install或npm i --package-lock-only重建package-lock.json

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 22:10:29