react-module-federation icon indicating copy to clipboard operation
react-module-federation copied to clipboard

Worker issue with NX module federation - Failed to execute 'importScripts' on 'WorkerGlobalScope': Module scripts don't support importScripts()

Open ashish-nagose-incontact opened this issue 2 years ago • 1 comments

While using module federation with worker created using comlink, when I browse application after serve, I get below error

image

Because of above error, not able to execute any functionality on worker thread.

PS: We are using same worker in nx application without module federation for more than a year where it works smoothly.

Are there any specific config changes to be done to make it work with Module federation?

I have added sample worker in reference repo and changes can be found at https://github.com/ashish-nagose-incontact/react-module-federation-with-worker

Yarn install and nx serve host --devRemotes=shop,cart --> to run the application

This error occurs in both host app and shop (wherein worker is incorporated).

We have tried blob approach as mentioned below after which error goes away but worker thread code never gets executed.

export function initUtilWorker() { const workerContent = UtilWorker.toString(); const blob = new Blob([workerContent], { type: 'application/javascript' }); const worker_script = URL.createObjectURL(blob); const worker = new Worker(new URL(worker_script, import.meta.url), { name: 'util-worker', type: 'module', }); return wrap<UtilWorker>(worker);

Please let us know if any additional information required.

ashish-nagose-incontact avatar Dec 15 '22 10:12 ashish-nagose-incontact

Is there any update or workaround on this issue, I am also facing the same issue. Error Message "Module scripts don't support importScripts()"

ankurrai2602 avatar Jan 17 '24 10:01 ankurrai2602