但是,当你升级webpack4 ---->webpack5时,如果你的版本是webpack-cli 4*时,就会报错
Error: Cannot find module 'webpack-cli/bin/config-yargs'
"webpack": "^5.36.0",
"webpack-cli": "^4.6.0",
"webpack-dev-server": "^3.11.2"
这是,因为在webpack-cli 4*中,作者删除了config-yargs,所以会报错。
这里有两种解决方案
- 临时解决方案:将webpack-cli版本降级到webpack-cli 3*
- 终极解决方案:修改配置文件,使用webpack serve替代webpack-dev-server也就是将配置项的
"dev": "webpack-dev-server --open"
改为"dev": "webpack serve --open"
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"dev": "webpack serve --open"
},
"keywords": [],
"author": "",
"license": "ISC",
}