Error: Rule can only have one resource source (provided resource and test + include + exclude) in {.

vue-cli项目运行npm run dev / npm run serve后报错:

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": [

原因:

某些新版本的库要求 webpack@5,更新依赖时,根据依赖选择的规则,就以 webpack@5 作为主依赖安装。然而 @vue/cli 依赖 webpack@4,它自带的 webpack 配置无法兼容 webpack@5 ,于是就报错,不能继续编译。如果你也在使用 @vue/cli,那么请不要贸然升级 webpack@5。

解决方案:

  1. 先删掉 node_modules 和 package-lock.json
  2. 手动在 package.json 的 devDependencies 里添加 “webpack”: “^4.23.0”,
  3. 重新安装全部依赖: npm install
  4. 重新运行,发现问题解决

参考文章:
https://blog.meathill.com/fe-tool-chain/how-to-fix-error-rule-can-only-have-one-resource-source-provided-resource-and-test-include-exclude.html

你可能感兴趣的:(BUG心得,vue,bug)