webpackcli和webpack-dev-server兼容问题

谷梁嘉运
2023-12-01

项目配置

"devDependencies": {
    "cross-env": "^7.0.3",
    "html-webpack-plugin": "^5.2.0",
    "ts-loader": "^8.0.17",
    "webpack": "^5.23.0",
    "webpack-cli": "^4.5.0",
    "webpack-dev-server": "^3.11.2"
  }

当使用官方给出方式启动webpack-dev-server时会报错,

node:internal/modules/cjs/loader:903
  throw err;
  ^

Error: Cannot find module 'webpack-cli/bin/config-yargs'

处理

"start:dev": "cross-env NODE_ENV=development webpack serve --open Chrome.exe"

只需要在srcipt中加入上面的命令即可(注意cross-env NODE_ENV=development是个人设置的环境模式,可以不用写)

 类似资料: