3

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.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Work
  • 31
  • 1

1 Answers1

0

You can get answer from this link: https://medium.com/@krishnachirumamilla/content-security-policy-worker-src-cd06ecfa2fe8

I am working on micro frontends and faced the same problem and solved using the slution in the link

and also I used below solution to achieve https://github.com/maxime1992/demo-webworker-library/blob/master/projects/fibonacci-webworker/src/lib/fibonacci.token.ts

  • In your answer you need to explain the answer to the question. Right now you have only provided links without any context. Please update your answer and explain how the references answer the question. – Dylan L. Mar 31 '22 at 05:59
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 31 '22 at 05:59