运行webpack-dev-server——config config/webpack.dev.js——progress——profile——watch——content-base src/时出错。下面是错误日志:
module.js:442
throw err;
^
Error: Cannot find module 'webpack/bin/config-yargs'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
我已经安装了以下依赖项(没有指定任何特定版本)
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2"
此错误出现在yarn启动过程中,包中的以下条目。特定于脚本的Json。attr开始。
"scripts": {
"start": "webpack-dev-server --open",
"build": "webpack"
}
所以,webpack-dev-server——open正在寻找webpack-cli 3.3版本。我通过安装特定版本的webpack-cli工作包摆脱了这个错误。Json是这样的:
"webpack-cli": "3.3",
"webpack-dev-server": "^3.11.2"
但是,如果你不想降级webpack-cli版本,将"start": "webpack-dev-server——open"更新为"start": "webpack serve——open"
上面的答案对我都没用。如果你仍然得到这个错误,你可以试试这个,这解决了我的问题:
打开node_modules \ webpack-dev-server \ bin \ webpack-dev-server.js
修改第84行:require('webpack-cli/bin/config-yargs')(yargs);
To:
要求(webpack-cli / bin / config / config-yargs) (yargs);
修改第92行:const config =
Require ('webpack-cli/bin/convert-argv')(yargs, argv, {
To:
const config = require('webpack-cli/bin/utils/convert-argv')(yargs, argv, {