webpack: Split chunks are not being loaded in the webworker target

Bug report

What is the current behavior?

The chunks are not imported (no occurrences of importScripts in entry chunks) so an error is thrown:

Uncaught TypeError: Cannot read property 'call' of undefined        worker-a.js:20
__webpack_require__ @ worker-a.js:20
(anonymous) @ worker-a.js:93
__webpack_require__ @ worker-a.js:20
(anonymous) @ worker-a.js:84
(anonymous) @ worker-a.js:87

If the current behavior is a bug, please provide the steps to reproduce.

Repo: https://github.com/Alexendoo/bugs/tree/master/02-webpack-worker-chunks Hosted: https://alexendoo.github.io/bugs/02-webpack-worker-chunks/ (nothing to display, just the errors in console)

The above setup has two entries, worker-a and worker-b that have a common shared dependency on shared.js, it sets minSize: 0 and chunks: "initial" in splitChunks to force a separate chunk to be created

The output of running webpack can be seen in dist/, neither worker-a.js nor worker-b.js import worker-a~worker-b.js

The bug also occurs when adding a named chunk to cacheGroups

What is the expected behavior?

Both worker-a.js and worker-b.js should import the chunk in worker-a~worker-b.js, through importScripts or some other mechanism

Other relevant information: webpack version: 4.16.5 Node.js version: 10.7.0 Operating System: Windows 10 Additional tools: none

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 15 (6 by maintainers)

Commits related to this issue

Most upvoted comments

On my side, I’m using import _ from 'lodash' in my worker. It does work but instead of loading the lodash chunk (using importScript) that was generated by the main app, it copies the full lodash codebase inside my worker file. That is a shame since it’s making a 13kb worker into a 1.3 Mb one!

I hope initial chunks will be loaded properly soon 😉.

If I can help, I would be glad to, but I have to admit I have no idea as to how to fix this. I looked a little in the codebase but it is hard to get to know it right now.