I have a small setup with webpack module federation, one container app and one remote. The remote is exposing itself completely and the container is consuming it to show it after clicking a navigation link like /users
.
The container is reachable at localhost:8080
, the remote at localhost:3001
Now, the remote is using mockup service worker (https://mswjs.io/), which works fine when visiting the app directly. When called through the container, an error comes up:
Uncaught (in promise) Error: [MSW] Failed to register a Service Worker for scope ('http://localhost:8080/') with script ('http://localhost:8080/mockServiceWorker.js'): Service Worker script does not exist at the given path.
I also tried setting the scope with
worker.start({
serviceWorker: {
options: {
scope: "http://localhost:3001",
},
},
})
which resolves in an error
Failed to register a ServiceWorker: The origin of the provided scope ('http://localhost:3001') does not match the current origin ('http://localhost:8080').
Does anyone have experiences with this? Using service workers in remotes with module federation? How to call them in the container?