webpack编译遇到的问题:Error: Cannot find module 'webpack-cli/bin/config-yargs'

运行npm run dev遇到的问题:Error: Cannot find module 'webpack-cli/bin/config-yargs'

// 当前package.json 文件
"devDependencies": {
    "webpack": "^5.2.0",
    "webpack-cli": "^4.1.0",
    "webpack-dev-server": "^3.11.0"
}

问题引用:

问题解决参考: Error: Cannot find module 'webpack-cli/bin/config-yargs' #1948

If you upgrade webpack to 5. *, and webpack cli to 4. *, an error will be reported:

Error: Cannot find module 'webpack-cli/bin/config-yargs'
Temporary solution: Back off webpack cli to version 3. * for example:

"webpack-cli": "^ 3.3.12"

解决:

  1. 卸载当前的 webpack-cli npm uninstall webpack-cli

  2. 安装 webpack-cli 3.* 版本 npm install webpack-cli@3 -D

webpack-dev-server ^3 需要安装webpack-cli ^3

// package.json文件
"devDependencies": {
    "webpack": "^5.2.0",
    "webpack-cli": "^3.3.12",
    "webpack-dev-server": "^3.11.0"
}

思考:

遇到问题首先到github项目的Issues中,检索一下相关问题,比在百度谷歌上直接搜索非官方解决方案好得多。

posted @ 2020-11-07 17:55  jiangxiaobo  阅读(4180)  评论(0编辑  收藏  举报