GoogleChromeLabs / GoogleChromeLabs/comlink

Issue with Comlink and Module Federation in Remote App Worker Implementation

Open
#677 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
12.8k
Forks
435
PR merge metrics
No merged PRs in 30d

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
1. Set up a host app and a remote app using Module Federation.
2. Add a worker to the remote app and integrate Comlink.
3. Access the remote app from the host app.
4. 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.