2
Node.js报错处理“error: cannot find module semver”
source link: https://www.fly63.com/article/detial/12681
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
更新日期: 2024-03-07阅读: 92标签: node分享
扫一扫分享
使用 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
希望这样能解决问题!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK