vue-cli: "Rule can only have one resource source" failure occurs when running server or building for production

Version

4.5.8

Environment info

System:
    OS: macOS 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
  Binaries:
    Node: 14.14.0 - ~/.nvm/versions/node/v14.14.0/bin/node
    Yarn: Not Found
    npm: 6.14.8 - ~/.nvm/versions/node/v14.14.0/bin/npm
  Browsers:
    Chrome: 86.0.4240.80
    Edge: Not Found
    Firefox: 79.0
    Safari: 14.0
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.2.1
    @vue/babel-helper-vue-transform-on:  1.0.0-rc.2
    @vue/babel-plugin-jsx:  1.0.0-rc.3
    @vue/babel-plugin-transform-vue-jsx:  1.2.1
    @vue/babel-preset-app:  4.5.8
    @vue/babel-preset-jsx:  1.2.3
    @vue/babel-sugar-composition-api-inject-h:  1.2.1
    @vue/babel-sugar-composition-api-render-instance:  1.2.1
    @vue/babel-sugar-functional-vue:  1.2.2
    @vue/babel-sugar-inject-h:  1.2.2
    @vue/babel-sugar-v-model:  1.2.3
    @vue/babel-sugar-v-on:  1.2.3
    @vue/cli: ^4.5.8 => 4.5.8
    @vue/cli-overlay:  4.5.8
    @vue/cli-plugin-babel: ^4.5.8 => 4.5.8
    @vue/cli-plugin-eslint: ^4.5.8 => 4.5.8
    @vue/cli-plugin-router:  4.5.8
    @vue/cli-plugin-vuex:  4.5.8
    @vue/cli-service: ^4.5.8 => 4.5.8
    @vue/cli-shared-utils:  4.5.8
    @vue/cli-ui:  4.5.8
    @vue/cli-ui-addon-webpack:  4.5.8
    @vue/cli-ui-addon-widgets:  4.5.8
    @vue/compiler-core:  3.0.1
    @vue/compiler-dom:  3.0.1
    @vue/compiler-sfc:  3.0.1
    @vue/compiler-ssr:  3.0.1
    @vue/component-compiler-utils:  3.2.0
    @vue/preload-webpack-plugin:  1.1.2
    @vue/reactivity:  3.0.1
    @vue/runtime-core:  3.0.1
    @vue/runtime-dom:  3.0.1
    @vue/shared:  3.0.1
    @vue/web-component-wrapper:  1.2.0
    eslint-plugin-vue: ^7.1.0 => 7.1.0
    typescript:  3.9.7
    vue: ^2.6.10 => 2.6.12 (3.0.1)
    vue-cli-plugin-apollo:  0.21.3
    vue-codemod:  0.0.4
    vue-eslint-parser:  7.1.1
    vue-hot-reload-api:  2.3.4
    vue-loader:  15.9.3 (16.0.0-beta.8)
    vue-style-loader:  4.1.2
    vue-template-compiler: ^2.6.10 => 2.6.12
    vue-template-es2015-compiler:  1.9.1
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

  • npm install
  • vue-cli-service build or vue-cli-service serve

What is expected?

To be built correctly

What is actually happening?

Error occurs:

Error: Rule can only have one resource source (provided resource and test   include   exclude) in {
  "exclude": [
    null
  ],
  "use": [
    {
      "loader": "./node_modules/cache-loader/dist/cjs.js",
      "options": {
        "cacheDirectory": "./node_modules/.cache/babel-loader",
        "cacheIdentifier": "d7e2daba"
      },
      "ident": "clonedRuleSet-38[0].rules[0].use[0]"
    },
    {
      "loader": "/Users/vp/nuxeo/nuxeo-insight-ui/node_modules/babel-loader/lib/index.js",
      "options": "undefined",
      "ident": "undefined"
    }
  ]
}

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 63
  • Comments: 54 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Can people stop posting the ā€œsolutionā€ of not using webpack 5? Itā€™s not that new anymore, and many packages require it.

Vue needs to support this.

I can confirm that downgrading to "webpack": "^4.45.0" works

It can be resolved with the following commands npm uninstall sass-loader npm install sass-loader@^10.1.1 --save-dev If the version of webpack is 5 then downgrade to any version between 4 and 5 npm uninstall webpack npm install webpack@^4.0.0 --save-dev

For me this issue appeared after updating my sass-loader. Fixed by downgrading to "sass-loader": "^10.1.1"

The problem still exists, and thatā€™s really infuriating. The solution is NOT to downgrade to a lower version of webpack or whatever package. One should be able to use it with node 16 (indeed, if you want to use this version, webpack 5 is required by some other packages).

This is getting ridiculous. I also have this problem. I just reverted old packege-lock.json and it works.

Why It was possible to properly install dependencies few weeks ago and now it is not possible? I even didā€™t change anything!

Itā€™s insane how fragile our dependencies are.

je veux migrer du version 4 Ć  5 , donc la solution proposer au dessus ne me convient pas, y a t il une autre solution ?

Itā€™s not a node version issue but a webpack v5 issue

npm uninstall webpack npm install webpack@^4.0.0 --save-dev

Is downgrading to Webpack 4.x.x a good solution?

For what itā€™s worth, I was having the same issue. Latest npm 7 handles peer dependencies in a different way than npm 6.

Following some advice in https://github.com/nuxt/nuxt.js/issues/8277 I ran npm i --legacy-peer-deps which drops webpack 5 from my package-lock.json and the build now works as expected.

This error raises by combination of @vue/cli-plugin-babel and vue-loaderā€™s plugin-webpack5.js. webpack 5 looks reject combining test / include / exclude with resource, and plugin-webpack5.js always add default resource function.

Here is the project example (sorry its dirty but simple) - https://github.com/vpasquier/vuejscli-repro

The problem is related to webpack 5 (https://github.com/vpasquier/vuejscli-repro/blob/master/my-project/package.json#L20)

This is the only thing iā€™ve added as dependency from the default vuejs bootstrap. Iā€™ve reverted my project to 4.x.x and it works well. They have released recently.

It can be resolved with the following commands npm uninstall sass-loader npm install sass-loader@^10.1.1 --save-dev If the version of webpack is 5 then downgrade to any version between 4 and 5 npm uninstall webpack npm install webpack@^4.0.0 --save-dev

This worked well for me on vue3 and TypeScript setup

Dialing it back to "sass-loader": "^10.1.1" in package.json worked for me. I appear to be on webpack@4.46.0 already.

Just confirmed this with an actual project. It works with Webpack 4.44.2 but fails with anything 5.x.x

npm uninstall webpack npm install webpack@^4.0.0 --save-dev

This doesnā€™t solve the described issue, is only a bandaid

This is getting ridiculous. I also have this problem. I just reverted old packege-lock.json and it works.

Why It was possible to properly install dependencies few weeks ago and now it is not possible? I even didā€™t change anything!

Itā€™s insane how fragile our dependencies are.

Totally agree with @zawadsoon. It is incredible how we are overexposed to dependencies. From a project up and running to a project full of unknown errors due to 3rd party libs.

None of those actually worked for me.

But Vue should support Webpack 5.x or at least provide instructions on how to configure Webpack 5.x

Just in case anyone has the issue I had with this, I thought I would share.

Basically for me, the problem was due to one package I was using having a dependancy on css-loader, which since version 6, has moved to using webpack 5. I suspect this will keep happening while packages update to using webpack 5, so it may be a different package for you.

I could see the problem when trying to add webpack 4.46.0 as a dev dependancy npm i webpack@4.46.0 --save-dev I then checked the version css-loader switch to using webpack 5 and then included the version before as a dev dependancy. npm i css-loader@5.2.7 --save-dev. I could then also include webpack 4 as a dev depenadancy and everything was working again.

What a nightmare!! Hope that helps someone!!

Updating vue/cli* to >= 5.0.0-rc.1 solves this issue can i can now use webpack 5 and sass-loader > 10.2 The alternative is to downgrade to webpack 4 and sass-loader 10.2 Thanks, syldman.

It can be resolved with the following commands npm uninstall sass-loader npm install sass-loader@^10.1.1 --save-dev If the version of webpack is 5 then downgrade to any version between 4 and 5 npm uninstall webpack npm install webpack@^4.0.0 --save-dev

This worked for me. Thank you

all solution above not works for me.

Mine is the monorepo repository. After webpack (4/5) is referenced in a package, the CLI cannot be started, and these two packages must be deleted.

At first I thought it was a webpack 5 problem until I switched back to webpack 4, the problem still existed.

For me, vue-cli is really a black box

I found a solution but in my case I believe it was somewhat related to the Quasar Framework dependencies my project was using. But here are some steps that helped me out:

I started using Node v12 (which is recommended by many frameworks as it is the last LTS version released) and forced the project to use ā€œcore-jsā€ dependency in version 3, Iā€™ve also seen some folks saying that version 2 also worked for them, but for me it only worked on 3.

I discovered that my problem specifically was related to the Quasar Framework getting updated to v2, and that there are plenty of modifications one has to do to make the project work correctly. If you are using Quasar, I highly recommend you to check this version upgrade tutorial: https://quasar.dev/quasar-cli/app-upgrade-guide

@shadow7412 it shouldnā€™t matter which version Iā€™m using. Vue should use whichever version it wants

  • my-project
    • dependencies
      • webpack 5.x.x
      • vue
        • webpack 4.x.x

I also have this issue in a laravel-mix powered vue project. Getting all kinds of dependency errors and it looks like laravel-mix is doing something.

In my case the issue was with the cache-loader that couldnā€™t work along webpack v5 and vue/cli v4.x requires cache-loader. vue/cli v5 moved to webpack 5 and vue/cli v5.0.0-beta.3 dropped requirement for cache-loader. So updating both webpack and vue/cli to v5 solved the issue. Now everything is working fine.

Is downgrading to Webpack 4.x.x a good solution?

Worked for me!

Having the same issue, moving from Node version 15 to 14 didnā€™t work for me. Here is the exception I am getting

Error: Rule can only have one resource source (provided resource and test + include + exclude) in {
  "exclude": [
    null
  ],
  "use": [
    {
      "loader": "~/node_modules/@vue/cli-plugin-babel/node_modules/cache-loader/dist/cjs.js",
      "options": {
        "cacheDirectory": "~/node_modules/.cache/babel-loader",
        "cacheIdentifier": "a8ec5012"
      },
      "ident": "clonedRuleSet-38[0].rules[0].use[0]"
    },
    {
      "loader": "~/node_modules/babel-loader/lib/index.js",
      "options": "undefined",
      "ident": "undefined"
    }
  ]
}
    at checkResourceSource (~/node_modules/@vue/cli-service/node_modules/webpack/lib/RuleSet.js:167:11)
    at Function.normalizeRule (~/node_modules/@vue/cli-service/node_modules/webpack/lib/RuleSet.js:198:4)
    at ~/node_modules/@vue/cli-service/node_modules/webpack/lib/RuleSet.js:110:20
    at Array.map (<anonymous>)
    at Function.normalizeRules (~/node_modules/@vue/cli-service/node_modules/webpack/lib/RuleSet.js:109:17)
    at new RuleSet (~/node_modules/@vue/cli-service/node_modules/webpack/lib/RuleSet.js:104:24)
    at new NormalModuleFactory (~/node_modules/@vue/cli-service/node_modules/webpack/lib/NormalModuleFactory.js:115:18)
    at Compiler.createNormalModuleFactory (~/node_modules/@vue/cli-service/node_modules/webpack/lib/Compiler.js:636:31)
    at Compiler.newCompilationParams (~/node_modules/@vue/cli-service/node_modules/webpack/lib/Compiler.js:653:30)
    at Compiler.compile (~/node_modules/@vue/cli-service/node_modules/webpack/lib/Compiler.js:661:23)
    at ~/node_modules/@vue/cli-service/node_modules/webpack/lib/Watching.js:77:18
    at AsyncSeriesHook.eval [as callAsync] (eval at create (~/node_modules/@vue/cli-service/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
    at AsyncSeriesHook.lazyCompileHook (~/node_modules/@vue/cli-service/node_modules/tapable/lib/Hook.js:154:20)
    at Watching._go (~/node_modules/@vue/cli-service/node_modules/webpack/lib/Watching.js:41:32)
    at ~/node_modules/@vue/cli-service/node_modules/webpack/lib/Watching.js:33:9
    at Compiler.readRecords (~/node_modules/@vue/cli-service/node_modules/webpack/lib/Compiler.js:529:11)

Thanks for submitting this issue! Due to our limited time, we ask you to include a reproduction link to a minimal full reproduction of your problem (for example in a GitHub repository) so we can find what is causing the issue. Thank you for your understanding!