Why does Webpack emit importScripts() for ES‑module Web Workers, causing runtime failure? #20862
kousik2000
started this conversation in
General
Replies: 1 comment 2 replies
-
|
Looks like you have |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We are migrating an Angular application from the default Angular CLI builder (@angular-devkit/build-angular) to ngx-build-plus to enable custom webpack configuration / Module Federation.
While doing so, we ran into a consistent runtime error in ES‑module Web Workers that does not occur when using the default Angular DevKit builder.
Uncaught TypeError: Failed to execute 'importScripts' on 'WorkerGlobalScope': Module scripts don't support importScripts(). at __webpack_require__.f.i (importScripts chunk loading:26:1) at ensure chunk:6:1 at Array.reduce (<anonymous>) at __webpack_require__.e (ensure chunk:5:1) at Array.map (<anonymous>) at __webpack_require__.x (startup chunk dependencies:3:1) at startup:3:1Environment
"@angular/cdk": "^20.2.9", "@angular/common": "^20.1.0", "@angular/compiler": "^20.1.0", "@angular/core": "^20.1.0", "@angular/forms": "^20.1.0", "@angular-architects/module-federation": "^20.0.0", "@angular-architects/module-federation-runtime": "^19.0.1", "@angular-architects/module-federation-tools": "^19.0.1", "ngx-build-plus": "^20.0.0",Code
`# worker listener
const worker = new Worker(new URL('./model.worker.ts', import.meta.url));
#worker.ts
const parserClass = new ModelParserClass();
addEventListener('message', ({ data }) => {
#code using parser class
})
#parser class
below are my parser class imports
import { UtilFunctions } from 'my-angular-shared-library';
import { cloneDeep } from 'lodash';
import { RailLive } from '@interfaces/common.interfaces';`
Any guidance, recommended configuration, or confirmation of best practices for using ES‑module Web Workers (especially with code splitting or Module Federation) would be greatly appreciated.
Thanks for your time and for the work you do on Webpack.
Beta Was this translation helpful? Give feedback.
All reactions