Webpack 5 multiple web workers with shared chunks failing to load
See original GitHub issueBug 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:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You have wrong
publicPath
, please usepublicPath: 'auto',
(I strongly recommend to use, also you will have relative URLs), why it happens, because we useimportScripts
, indist/static/js/worker-1.js
(in other worker too), so you haveimportScripts("./static/js/vendors-node_modules_lodash_lodash_js.js")
, and you have./static/js/static/js/vendors-node_modules_lodash_lodash_js.js
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