Skip to content
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

Split chunks are not being loaded in the webworker target #7879

Closed
Alexendoo opened this issue Aug 11, 2018 · 15 comments
Closed

Split chunks are not being loaded in the webworker target #7879

Alexendoo opened this issue Aug 11, 2018 · 15 comments

Comments

@Alexendoo
Copy link

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

@sokra
Copy link
Member

sokra commented Aug 13, 2018

Yes, splitting the initial chunks is (currently) not supported in WebWorkers. You must provide chunks: "async".

To get some kind of deduplication you could use import() in the entrypoints.

@Alexendoo
Copy link
Author

I see, thanks @sokra!

@prateekbh
Copy link

facing the same problem

@prateekbh
Copy link

I am using

optimization: {
    splitChunks: {
      cacheGroups: {
        commons: {
          chunks: 'all',
          test: /[\\/]node_modules[\\/]/,
          name: 'vendors',
        }
      }
    }
  }

does seem to load the vendors chunk

@webpack-bot
Copy link
Contributor

This issue had no activity for at least half a year.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@Alexendoo
Copy link
Author

.

@dannibje
Copy link

Any news on this? I have the exact same problem. But with node modules. The answer from @prateekbh does not fix it, I get the error

bootstrap:19 Uncaught TypeError: Cannot read property 'call' of undefined at r (bootstrap:19) at Module.<anonymous> (webworker1.js:1) at Module.131 (webworker1.js:8) at r (bootstrap:19) at bootstrap:83 at bootstrap:83

@qraynaud
Copy link

qraynaud commented Sep 3, 2019

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.

@prateekbh
Copy link

I never had an anwer @dannibje 😛

@webpack-bot
Copy link
Contributor

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@qraynaud
Copy link

qraynaud commented Dec 4, 2019

This is still a real issue even if it's inactive. I don't understand this bot. I never knew waiting issues out was a way to fix them ! 😛

@wood1986
Copy link
Contributor

will it support in webpack 5?

@onzag
Copy link

onzag commented Jan 18, 2020

So any way to import from a web worker my commons file?...

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

@sokra
Copy link
Member

sokra commented Oct 29, 2020

This is still a real issue even if it's inactive. I don't understand this bot. I never knew waiting issues out was a way to fix them ! 😛

We can't fix everything. Piling up issues neither fixes them.

But anyway this is fixed in webpack 5

motin added a commit to motin/firefox-translations that referenced this issue Apr 27, 2021
motin added a commit to mozilla-extensions/firefox-translations that referenced this issue May 4, 2021
* Automatically download the appropriate translation models, vocabularies and lexical shortlists if not already loaded

* Configure bergamot models base url based on development build or not

* Invalidate circle ci cache so that we can be sure that circle tests passes on a clean checkout and subsequent builds will have the bergamot-models already downloaded

* Use typescript for the translation worker integration code as well

* Only download model files if not already previously downloaded

* Add notice in bergamot-translator-worker.ts about the contents being imported from elsewhere

* Add some type declarations to translation worker

* Move out model download code to separate function

* Add license headers

* Add simple in-browser test for model downloading

* Add test that verifies that downloaded model files caching works

* Add test that verifies that downloading model files for another language pair works

* Replace cache.add with fetch+cache.put combo so that we have more control over what and when to cache downloaded model files

* Add fetch progress callback, track total bytes transferred and measure the time it takes to download model files

* Don't use third party lib for fetch progress callbacks + Ensure proper tracking of total bytes transferred

* Serve model files gzipped from local http server

* Handle missing language pair download errors gracefully

* Verify the hash of downloaded model files

* Invalidate circle ci cache

* Exclude 'translation-worker' webpack target from split chunks optimization since it leads to a broken web worker bundle (webpack/webpack#7879)

* Add file sizes to model registry (useful for tracking download progress) + Don't attempt to persist model files if remaining quota suggest that it won't work

* Add a few additional sanity/error checks

* Add in-browser test for failing download integrity checks

* Cleanup model download code

* Catch more load model errors

* Pin bergamot-models revision so that the expected set of models are imported locally

* Clean up import-bergamot-translator.sh

* Restored translation for language pairs that re-use vocab files from the reverse direction

* Cleanup and tweaks

* Summarize periodical updates on total language pair download progress

* Use more already available typings in translation-worker

* Download progress hooked up through all abstraction layers and displayed as text in the translation infobar

* Move translateAllFramesInTab to separate file

* Some cleanup

* Record model download time metric in post-translation telemetry

* General cleanup and test improvements

* Add model download time assertions in e2e tests
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

9 participants