-
Notifications
You must be signed in to change notification settings - Fork 421
Open
Description
I am consuming a remote application inside a host application using Module Federation. The remote application includes a worker implementation.
- Working Scenario: When using raw worker implementation, everything functions as expected.
- Issue: When integrating Comlink with the worker, I encounter the following error:
Error: SecurityError: Failed to construct 'Worker': Script at 'http://localhost:3000/static/js/src_worker_js.chunk.js' cannot be accessed from origin 'http://localhost:3001/'.
Context
- Host app runs on
http://localhost:3001. - Remote app runs on
http://localhost:3000. - Worker script (
src_worker_js.chunk.js) is being accessed cross-origin.
Steps to Reproduce
- Set up a host app and a remote app using Module Federation.
- Add a worker to the remote app and integrate Comlink.
- Access the remote app from the host app.
- Observe the error when trying to initialize the worker.
Expected Behavior
The worker with Comlink should function seamlessly without cross-origin access issues.
Actual Behavior
The browser throws a SecurityError, preventing the worker from being constructed.
Potential Cause
The issue seems related to cross-origin restrictions when loading the worker script.
Environment
- Host app:
http://localhost:3001 - Remote app:
http://localhost:3000 - Module Federation setup with Webpack.
Additional Notes
- This issue is specific to using Comlink. Raw worker implementation does not encounter this problem.
- Any insights on resolving this cross-origin issue with Comlink would be greatly appreciated.
Repo: https://github.com/KVPasupuleti/cra-module-federation
Branch : comlink-worker-issue-mfe
Metadata
Metadata
Assignees
Labels
No labels