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.

Webpack 5 multiple web workers with shared chunks failing to load

See original GitHub issue

Bug report

What is the current behavior? Multiple web workers within webpack are unable to load shared chunks from the correct url due to the workers self.location being different than the window.location of the original page

If the current behavior is a bug, please provide the steps to reproduce. I have created a demo project to reproduce the issue here: https://github.com/ItsOnlyBinary/webpack-issue

please see the README.md for how to start the demo

What is the expected behavior? Webpack should be able to detect its relative url for the shared chunks within the web workers so they are loaded from the correct url.

Other relevant information: webpack version: 5.44.0 Node.js version: v12.16.3 Operating System: Windows Additional tools:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
alexander-akaitcommented, Aug 12, 2021

You have wrong publicPath, please use publicPath: 'auto', (I strongly recommend to use, also you will have relative URLs), why it happens, because we use importScripts, in dist/static/js/worker-1.js (in other worker too), so you have importScripts("./static/js/vendors-node_modules_lodash_lodash_js.js"), and you have ./static/js/static/js/vendors-node_modules_lodash_lodash_js.js

1reaction
qingwufongcommented, Aug 10, 2021

Please provide example how we can reproduce, I think you have publicPath option for HtmlWebpackPlugin

We found that the version of webpack after 5.31 have this problem, but 5.22 is OK. and reproduce the issue here: https://github.com/qingwufong/webpack-issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack: Common chunks for code shared between ...
Webpack loads chunks with document.createElement('script') and document.head.appendChild() sequence, which is not available in worker ...
Read more >
The case for Workers · Issue #6472 · webpack ... - GitHub
Currently a target: "web" compilation and a target: "webworker" compilation can't share chunks, because they are using different ways to lazy- ...
Read more >
Web Workers | webpack - JS.ORG
As of webpack 5, you can use Web Workers without worker-loader . Syntax. new Worker(new URL('./worker.js', import.meta.url)); // or customize the chunk name ......
Read more >
worker-loader - webpack - JS.ORG
To use Web Workers in webpack 5, see https://webpack.js.org/guides/web-workers/. Getting Started. To begin, you'll need to install worker-loader : $ npm install ...
Read more >
Code Splitting - webpack
It can be used to achieve smaller bundles and control resource load prioritization ... The dependOn option allows to share the modules between...
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