运行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版本(和Webpack命令行):

npm install --save-dev webpack webpack-cli webpack-dev-server webpack-merge

如果您不使用上面提到的任何一种,请随意省略。

其他回答

我忘记安装webpack-cli。所以我按照命令运行,问题得到了解决。

npm i -D webpack-cli

我也遇到过类似的问题。我认为这与webpack版本有关。更改webpack版本后,最新的一切都很好…

请使用webpack服务运行webpack-dev-server

webpack serve --config config/webpack.dev.js --progress --profile --watch --content-base src/

在我的案例中,解决方案就是使用以前的版本

"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"

解决方案

package.json

"scripts": {
    "startdev": "webpack serve --mode development --env development --hot --port 3000"
    ...
    ...
  },
"devDependencies": {
...
    "webpack": "^5.10.1",
    "webpack-cli": "^4.2.0"
 },

控制台

$ npm run startdev