Node.js报错处理“error: cannot find module semver”
使用 npm 安装软件包时,可能会遇到 "error: cannot find module semver"(错误:找不到 semver 模块)错误。
+ npm install
...
...
module.js:340
throw err;
^
Error: Cannot find module 'semver'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)导致该错误的原因是 package-lock.json 或 yarn.lock 损坏。最常见的原因是节点版本发生了变化。
解决方案
修复方法非常简单。我们需要删除 node_modules 文件夹和锁文件。
rm-rf node_modules package-lock.json yarn.lock然后,我们需要清除 npm 缓存:
npm clean cache --force并重新安装软件包:
npm i这在大多数情况下应能修复错误,如果不能,您可能需要卸载并重新安装 Node 才能修复错误。
如果您使用的是自制软件:
brew uninstall --force node
brew install node希望这样能解决问题!
本文内容仅供个人学习/研究/参考使用,不构成任何决策建议或专业指导。分享/转载时请标明原文来源,同时请勿将内容用于商业售卖、虚假宣传等非学习用途哦~感谢您的理解与支持!