question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VueLoaderPlugin causes loaders to run several times

See original GitHub issue

Version

15.0.0

Reproduction link

https://github.com/killerDJO/vue-loader-minimal

Steps to reproduce

Prererquisites:

  • ts-loader is used and has options specified (Important!).
  • SFC with referenced TypeScript file is used.

Run webpack build using mentioned configuration. Rules might look like this:

module: {
    rules: [
        {
            test: /\.ts$/,
            loader: "ts-loader",
            options: {},
            exclude: [/node_modules/]
        },
        {
            test: /\.vue$/,
            loader: "vue-loader",
        }
    ]
},
resolve: {
    extensions: [".ts"],
},
plugins: [
    new VueLoaderPlugin()
],

What is expected?

Build is finished successfully.

What is actually happening?

Build failed.


In the current implementation VueLoaderPlugin clones webpack rules and modifies them to run on .vue files. However, this leads to an issues when a file is referenced from .vue component (e. g. <script src="./App.ts" lang="ts"></script>). In this case the file can be matched by two rules (original and cloned) and ts-loader will be executed two times, with second time executing using output of the first run. This will happend only if “options” object is specified, because otherwise webpack will use a single loader for two rules (VueLoaderPlugin removes “options” during rules cloning, so only original rule will have options).

Aforementioned behaviour has been observed for ts-loader, but is likely to occur for scss/sass loaders as well.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
yevhenii-andrushchakcommented, May 2, 2018

Unfortunately, it doesn’t work exactly like this, so .vue.ts cannot be used. It is possible to use resourceQuery or issuer to check for .ts files imported from .vue files, but in this case it will fail for other (non-vue) ts files (entry file will not have an issuer and usual ts files will not have a resourceQuery, so webpack will fail such rules since it doesn’t support checks for an empty value). It might be possible to get this to work using some tricks, but it’s much simpler to just remove options for now.

1reaction
yevhenii-andrushchakcommented, May 2, 2018

@ericdrobinson This is exactly the issue I ran into. For me it also worked when I removed options from loader. Another workaround I can imagine (if options are neccessary) is to modify ‘test’ parameter, e.g. it can check only for files which are outside of vue components folder (in this case these files will be compiled only by cloned ts-loader, which has own test).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Calling VueLoaderPlugin() causes 'findIndex' undefined error
When fiddling around trying to get the vue-loader to work, at some point I got an error leading me to update webpack to...
Read more >
Migrating from v14 - Vue Loader
We are in the process of upgrading Vue CLI 3 beta to use webpack 4 + Vue Loader v15, so you might want...
Read more >
vue-loader - npm
Start using vue-loader in your project by running `npm i ... causing the component to reload despite only the template being edited.
Read more >
Setup VueJs with Webpack 4 - WebOmnizz
Of cause it saves a lot of time and does not require setting up any ... css-loader and vue-style-loader so we can use...
Read more >
Building micro-frontends with webpack's Module Federation
By page ⁠— In our frontend applications, sometimes having different pages run at the same time in the browser can cause a crash...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found