Skip to content

[webpack-cli] Error: [VueLoaderPlugin Error] No matching use for vue-loader is found. Make sure the rule matching .vue files include vue-loader in its use. #1826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
masx200 opened this issue May 13, 2021 · 10 comments

Comments

@masx200
Copy link

masx200 commented May 13, 2021

Version

15.9.7

Reproduction link

https://github.com/masx200/webpack-react-vue-spa-awesome-config/tree/54ae5e83a1c55b08f2107faced36e66a97aa7a6b/

Steps to reproduce

 webpack  --config ./release/config/webpack.config.js     --mode=production         

What is expected?

There should be no errors.

What is actually happening?

[webpack-cli] Error: [VueLoaderPlugin Error] No matching use for vue-loader is found.
Make sure the rule matching .vue files include vue-loader in its use.
at VueLoaderPlugin.apply (/data/data/com.termux/files/home/webpack-react-vue-spa-awesome-config/node_modules/.pnpm/[email protected]_05b8f49ac146c83a596ecaf17314083d/node_modules/vue-loader/lib/plugin-webpack5.js:96:13)
at createCompiler (/data/data/com.termux/files/home/webpack-react-vue-spa-awesome-config/node_modules/.pnpm/[email protected][email protected]/node_modules/webpack/lib/webpack.js:74:12)
at create (/data/data/com.termux/files/home/webpack-react-vue-spa-awesome-config/node_modules/.pnpm/[email protected][email protected]/node_modules/webpack/lib/webpack.js:123:16)
at webpack (/data/data/com.termux/files/home/webpack-react-vue-spa-awesome-config/node_modules/.pnpm/[email protected][email protected]/node_modules/webpack/lib/webpack.js:131:47)
at WebpackCLI.f [as webpack] (/data/data/com.termux/files/home/webpack-react-vue-spa-awesome-config/node_modules/.pnpm/[email protected][email protected]/node_modules/webpack/lib/index.js:54:15)
at WebpackCLI.createCompiler (/data/data/com.termux/files/home/webpack-react-vue-spa-awesome-config/node_modules/.pnpm/[email protected]_172ba78252e4c29f98987ba985b0c3fc/node_modules/webpack-cli/lib/webpack-cli.js:1845:29)
at async WebpackCLI.buildCommand (/data/data/com.termux/files/home/webpack-react-vue-spa-awesome-config/node_modules/.pnpm/[email protected]_172ba78252e4c29f98987ba985b0c3fc/node_modules/webpack-cli/lib/webpack-cli.js:1952:20)
at async Command. (/data/data/com.termux/files/home/webpack-react-vue-spa-awesome-config/node_modules/.pnpm/[email protected]_172ba78252e4c29f98987ba985b0c3fc/node_modules/webpack-cli/lib/webpack-cli.js:742:25)
at async Promise.all (index 1)
at async Command. (/data/data/com.termux/files/home/webpack-react-vue-spa-awesome-config/node_modules/.pnpm/[email protected]_172ba78252e4c29f98987ba985b0c3fc/node_modules/webpack-cli/lib/webpack-cli.js:1289:13)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


https://github.com/masx200/webpack-react-vue-spa-awesome-config/blob/54ae5e83a1c55b08f2107faced36e66a97aa7a6b/release/config/webpack.config.js

https://github.com/masx200/webpack-react-vue-spa-awesome-config/blob/54ae5e83a1c55b08f2107faced36e66a97aa7a6b/package.json

webpack version 5.37.0
nodejs version 14.15.4

@fryght
Copy link

fryght commented May 19, 2021

It seems to only load the parser rule when it is present in the Webpack configuration (I ran into the same issue). Not sure if this is an issue in this package or in Webpack itself.

@masx200
Copy link
Author

masx200 commented May 19, 2021

It seems to only load the parser rule when it is present in the Webpack configuration (I ran into the same issue). Not sure if this is an issue in this package or in Webpack itself.

https://github.com/masx200/webpack-react-vue-spa-awesome-config/blob/54ae5e83a1c55b08f2107faced36e66a97aa7a6b/release/config/webpack.config.js#L194

https://webpack.docschina.org/configuration/module/#ruleparser

https://webpack.js.org/configuration/module/#ruleparser

@zhangmingmeng
Copy link

所以这个问题怎么解决的啊,我哭辽o(╥﹏╥)o

So how can this problem be solved? I cried

@masx200
Copy link
Author

masx200 commented May 24, 2021

所以这个问题怎么解决的啊,我哭辽o(╥﹏╥)o

So how can this problem be solved? I cried


{ parser: { requireEnsure: !1 } },

Just delete this code.

@Uniman-Su
Copy link

Uniman-Su commented May 31, 2021

I met this problem today, so I tried to debug the vue-loader code to solve this problem and succeeded.
I'm not sure whether I've met the same problem of you've met.
I met this with webpack 5, but it's ok with webpack 4.
Because of the code in file 'pluginWebpack5.js', row 44 to 60, there is something wrong in the loop.

for (const rawRule of rules) { // skip rules with 'enforce'. eg. rule for eslint-loader if (rawRule.enforce) { continue; } vueRules = match(rawRule, 'foo.vue'); if (!vueRules.length) { vueRules = match(rawRule, 'foo.vue.html'); } if (vueRules.length > 0) { if (rawRule.oneOf) { throw new Error([VueLoaderPlugin Error] vue-loader currently does not support vue rules with oneOf.); } rawVueRule = rawRule; break; } }

With webpack 5, the rules are passed in from head to tail, if a loader before vue-loader with a test like /.html$/ found, this loop will end. And a wrong loader will be passed to VueLoaderPlugin.

To solve this problem, you must write vue-loader rule before such a .html loader.

@korya
Copy link

korya commented Jun 26, 2021

Same here. After upgrading to webpack v5 the build started failing with the same error:

[webpack-cli] Error: [VueLoaderPlugin Error] No matching use for vue-loader is found.
Make sure the rule matching .vue files include vue-loader in its use.

Moving the rule for Vue files above all HTML rules fixed the problem.

The code to blame is

if (!vueRules.length) {
vueRules = ruleSet.exec({
resource: 'foo.vue.html'
})
}
. Not sure why it is needed.

@joshuafc
Copy link

joshuafc commented Jul 2, 2021

+1,found the same issue at "vue-loader": "^16.3.0", & "webpack": "^5.41.1",

@misterpancn
Copy link

The same problem I tried to assert in the source code and found that vue-loader would parse to

{
    test: /\.html$/,
    use: 'vue-html-loader'
},

, which was strange.

"vue-loader": "^15.9.8",
"webpack": "^5.50.0",

@benwalsh
Copy link

benwalsh commented Aug 7, 2024

I had a custom.js much as in the Shakapacker example that was setting the rules. In order to work around this (very old!) issue I had to remove the vue-loader rule from there and then unshift before setting the config:

const { generateWebpackConfig } = require('shakapacker');
const customConfig = require('./custom');
const newConfig = generateWebpackConfig(customConfig);
newConfig.module.rules.unshift({ test: /\.vue$/, use: 'vue-loader' });
module.exports = newConfig;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants