Angular Web Worker error after using Module Federation: importScripts not supported
I’m using Angular with ngx-build-plus and Webpack Module Federation.
I have a Web Worker like this:
const worker = new Worker(new URL('./model.worker.ts', import.meta.url));
Inside the worker, I import a parser class, and that parser imports a custom Angular library.
Issue
When I use the library inside the worker, I get runtime errors like:
Failed to execute 'importScripts' on 'WorkerGlobalScope':
Module scripts don't support importScripts()
or
Uncaught Error: Cannot find module '210'
Observation
- If I remove the library import → worker works
- If I keep it → worker fails
- Same code works fine with default Angular build, but breaks after using Module Federation
Question
- Why is this happening with webpack + Module Federation?
- Are shared libraries not supported inside Web Workers?
- What is the correct way to use dependencies inside workers in this setup?
Repo for reference: https://github.com/kousik2000/mfe-worker-repo