-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[differential loading + web workers] es5 worker doesn't load polyfills #15033
Comments
This is an interesting case. The short answer is "you need to manually include worker polyfills in the worker itself". Workers are self-contained entry points. This means that their JS bundle does not share any of the packages of your application. That's why they have their own tsconfig.json as well. If you import a big package in your app and in your worker, it will be loaded twice. If you import a big package in your app and in two workers, it will be loaded three times. They must be self contained because Web Worker run in background threads, so they need to contain all the code they need to run. Nothing so far implies that we couldn't automatically add polyfills though. We already know what polyfills you want for your app, and we also have custom polyfills for es5 and jit. We're fairly sure the app will need the custom es5/jit polyfills because But I don't think we should automatically add these to workers because polyfills can be fairly big and it's not very clear you will need them. Workers can be quite small if you're using them just to process data. The polyfills can be several times the size of a worker, and delay its startup. So I think the better approach for workers is to include polyfills they need directly. Polyfills that are only loaded on older browsers are a harder topic. We do some tricks in |
Thanks for the thorough reply. I'm aware of the general concept (or problem) of the workers being self-contained.
That's the problem exactly. Including them manually is fine, but you end up loading them unnecessarily most of the time. Can you think of a way to omit unneeded ones from the bundle rather than including needed ones? |
Maybe a feature check and loading only the missing APIs could do the trick? |
You'd still end up loading/parsing the whole bundle. |
I think at some point https://polyfill.io/ allowed you to make a call and it would give you what your browser lacked somehow. I'm not sure if it still does that. But the round trip might be worse than just including some polyfills directly. |
Didn't know that one! Nice. |
@j2L4e, yes, my suggestion was to add them by hand after a feature check but polyfill.io would do the trick by performing a Can we go ahead and close this issue? |
Seems to be the only reasonable way. Go ahead 👍 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 Bug report
Command
ng build --prod
Is this a regression?
No
Description
The es5 version of web workers doesn't load the polyfills the main application bundle loads. I'm experiencing this with
Promise
in IE11. The non-worker bundle runs fine asPromise
is properly polyfilled. The web worker doesn't run, however, becausePromise
is undefined.You can easily work around this using
import 'core-js/features/promise'
but in my opinion main code and worker code should be bundled in a consistent manner.🔬 Minimal Reproduction
🔥 Exception or Error
🌍 Your Environment
Anything else relevant?
Experienced in IE11 but the problem's a more general one.
The text was updated successfully, but these errors were encountered: