小工具知识网

当前位置: 首页 > 行业知识 > vue-cli项目因为webpack版本不兼容运行后报错

行业知识

vue-cli项目因为webpack版本不兼容运行后报错

2026-11-16 23:03:31 来源:互联网转载

vue-cli项���运行后报错:

Error: Rule can only have one resource source (provided resource and test + include + exclude) in {  "exclude": [    null  ],  "use": [    {      "loader": "G:\CustomerDay\customerday\node_modules\cache-loader\dist\cjs.js",      "options": {        "cacheDirectory": "G:\CustomerDay\customerday\node_modules\.cache\babel-loader",        "cacheIdentifier": "f25d7318"      },      "ident": "clonedRuleSet-38[0].rules[0].use[0]"    },    {      "loader": "G:\CustomerDay\customerday\node_modules\babel-loader\lib\index.js",      "options": "undefined",      "ident": "undefined"    }  ]}Error: Rule can only have one resource source (provided resource and test + include + exclude) in {  "exclude": [    null  ],  "use": [

原因:@vue/cli 依赖 webpack@4,它自带的 webpack 配置无法兼容 webpack@5 ,于是就报错,不能继续编译。如果在使用 @vue/cli,那么请不要贸然升级 webpack@5。

解决办法:

  • 删除node_modules 和 package-lock.json
  • 手动在 package.json 的 devDependencies 里添加 "webpack": "^4.47.0",(只要是4就好
  • 重新安装全部依赖:npm install

    一般情况可以解决,但如果出现以下这个错误:

    根据提示可以强制安装:npm install --force 或 npm install --legacy-peer-deps

上一篇:魔兽世界哪里找回服务器?

下一篇:怎么把网站服务器转移?