当前位置: 首页 > 工具软件 > module-server > 使用案例 >

webpack-dev-server 报错 Error: Cannot find module ‘webpack/bin/config-yargs‘

卫成和
2023-12-01

Error: Cannot find module 'webpack/bin/config-yargs'  报错 解决

> demo70@1.0.0 dev G:\000Code\10\11\demo70
> webpack-dev-server --port 3000

internal/modules/cjs/loader.js:1033
  throw err;
  ^

Error: Cannot find module 'webpack/bin/config-yargs'
Require stack:
- G:\000Code\10\11\demo70\node_modules\webpack-dev-server\bin\webpack-dev-server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1030:15)
    at Function.Module._load (internal/modules/cjs/loader.js:899:27)
    at Module.require (internal/modules/cjs/loader.js:1090:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at Object.<anonymous> (G:\000Code\10\11\demo70\node_modules\webpack-dev-server\bin\webpack-dev-server.js:56:1)
    at Module._compile (internal/modules/cjs/loader.js:1201:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
    at Module.load (internal/modules/cjs/loader.js:1050:32)
    at Function.Module._load (internal/modules/cjs/loader.js:938:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'G:\\000Code\\10\\11\\demo70\\node_modules\\webpack-dev-server\\bin\\webpack-dev-server.js'
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! demo70@1.0.0 dev: `webpack-dev-server --port 3000`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the demo70@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2020-11-19T02_43_49_770Z-debug.log
PS G:\000Code\10\11\demo70> npm uninstall webpack webpack-cli webpack-dev-server
npm WARN demo70@1.0.0 No description
npm WARN demo70@1.0.0 No repository field.

removed 535 packages in 8.81s

 

报错原因 : webpack-dev-server 的版本和 webpack 发生冲突

   解决办法 : 

   1 : 先把冲突的 webpack webpack-cli webpack-dev-server 全部卸载掉

 npm uninstall webpack webpack-cli webpack-dev-server

   2 : npm安装指定版本

npm i -D webpack@4.32.2  webpack-cli@3.3.2  webpack-dev-server@3.5.1  

   3 : 重新运行 npm run dev 

 

 

 类似资料: