react-module-federation
react-module-federation copied to clipboard
Worker issue with NX module federation - Failed to execute 'importScripts' on 'WorkerGlobalScope': Module scripts don't support importScripts()
While using module federation with worker created using comlink, when I browse application after serve, I get below error

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.
Is there any update or workaround on this issue, I am also facing the same issue. Error Message "Module scripts don't support importScripts()"