安装webpack-dev-server
包后,配置脚本"dev": "webpack-dev-server"
,然后执行npm run dev
发现报错:
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
从错误信息我们可以看到其实是webpack-cli
缺少了config-yargs
模块造成的,
我的包版本如下:
"devDependencies": {
"webpack": "^5.23.0",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2"
}
删除原来的webpack-cli
包,降低webpack-cli
的版本为 "^3.3.12"即可:
npm uninstall webpack-cli
npm install webpack-cli@3.3.12 --save-dev