启动项目npm run dev报错:
Cannot find module 'webpack/bin/config-yargs'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object. (D:\my\react-task\node_modules\webpack-dev-server\bin\webpack-dev-server.js:24:1)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10
错误原因:
一种说是webpack 和 webpack-dev-server版本不匹配
另一种是webpack4之后,将config-yargs放到了webpack-cli里面去了
(版本更改后的):
"webpack": "^3.8.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-server": "^2.9.7",
解决方案:
1.webpack 版本在 4 以上时
安装 webpack-cli,然后更新
npm install webpack-cli -D
npm update
2.修改webpack和webpack-dev-server版本
先删后改,卸载之后安装指定版本
//卸载版本
cnpm uninstall webpack -g
cnpm uninstall -g webpack-dev-server
//安装指定版本
cnpm install webpack@3.8.0 --save-dev
cnpm install webpack-dev-server@2.9.7 --save-dev
(不要纠结 -g 在前在后,据我实验无所谓。)