Cannot use a web worker with my microfrontend

Viewed 313

I just want to use a simple web worker in one of my single-spa react micro frontend. However when I initialize it, that doesn't work, the program cannot find the worker. I tried with the 2 following methods inside of my root.component.js:

The classic way ->

let myWorker = new Worker('./worker.js'); 

The error message printed is just:

GET http://example.com/worker.js 404 (Not Found)

The webpack way ->

let myWorker = new Worker(new URL('./worker.js', import.meta.url));

And the error message printed is

react_devtools_backend.js:4049 DOMException: Failed to construct 'Worker': Script at 'http://example.com:8001/src_worker_js.project-name.js' cannot be accessed from origin 'http://example.com'.

I'm a beginner with single-spa and webpack so I suppose I'm just not doing the correct method.

1 Answers
Related