欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Error: Cannot find module 'webpack-cli/bin/config-yargs' at Function.Module._resolveFilename

程序员文章站 2022-07-12 19:34:24
...

项目之前使用npm run start执行(“start”: “webpack-dev-server --open --config webpack.dev.js --watch --inline”)时正常,过了一段时间重新拉取代码,再次运行出现如下问题:

Error: Cannot find module 'webpack/bin/config-yargs'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> 
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

通过对比查找发现新拉取的代码install的webpack相关的包与之前的不一致,将package.json中的配置webpack相关的依赖包版本指定为固定版本:

-    "webpack": "^4.11.1",
-    "webpack-cli": "^2.1.4",
-    "webpack-dev-server": "^3.1.4",
-    "webpack-merge": "^4.1.2"
+    "webpack": "4.11.1",
+    "webpack-cli": "2.1.4",
+    "webpack-dev-server": "3.1.4",
+    "webpack-merge": "4.1.2"

即去掉版本号前面的 “^”,再次 npm install,执行 npm run start 就可以正常运行了。