Skip to content

fix(module-federation): enable ESM output for Angular rspack MF plugin#34839

Merged
FrozenPandaz merged 2 commits intomasterfrom
fix/34584-angular-rspack-mf-esm
Mar 20, 2026
Merged

fix(module-federation): enable ESM output for Angular rspack MF plugin#34839
FrozenPandaz merged 2 commits intomasterfrom
fix/34584-angular-rspack-mf-esm

Conversation

@FrozenPandaz
Copy link
Collaborator

Current Behavior

When using Angular + Rspack + Module Federation, the NxModuleFederationPlugin (Angular variant) sets library: { type: 'module' } on the Module Federation plugin config, which causes remoteEntry.js to emit ESM export statements. However, the compiler's experiments.outputModule and output.module flags are not set, so the MF runtime tries to load the remote entry as a classic script. This results in:

Uncaught SyntaxError: Unexpected token 'export' (at remoteEntry.js:48774:1)

This is especially broken during nx serve (dev server), because @nx/angular-rspack's createConfig only sets experiments.outputModule = true for production builds, not dev server builds.

Expected Behavior

The Angular rspack NxModuleFederationPlugin should ensure experiments.outputModule = true and output.module = true are set on the compiler when using library: { type: 'module' }, so that Module Federation works out of the box in both dev and production modes.

This aligns with how the Angular webpack MF config already handles it (in with-module-federation/angular/with-module-federation.ts).

Related Issue(s)

Fixes #34584
Fixes #33992

@FrozenPandaz FrozenPandaz requested a review from a team as a code owner March 15, 2026 00:03
@netlify
Copy link

netlify bot commented Mar 15, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit cd67302
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69bd7a50e73cda000893105b
😎 Deploy Preview https://deploy-preview-34839--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Mar 15, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit cd67302
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69bd7a50ebbd7e0007f0eaf2
😎 Deploy Preview https://deploy-preview-34839--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Mar 15, 2026

View your CI Pipeline Execution ↗ for commit cd67302

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 1h 5m 40s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 5s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 8s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-20 17:58:55 UTC

@FrozenPandaz FrozenPandaz requested a review from jaysoo March 16, 2026 21:28
@FrozenPandaz FrozenPandaz self-assigned this Mar 16, 2026
@FrozenPandaz FrozenPandaz requested a review from a team as a code owner March 20, 2026 16:03
…M output

Adds a browser-level test that navigates to the remote route to verify
remoteEntry.js loads correctly. This catches ESM runtime errors like
"Unexpected token 'export'" that only surface in the browser.
@FrozenPandaz FrozenPandaz force-pushed the fix/34584-angular-rspack-mf-esm branch from 6168031 to cd67302 Compare March 20, 2026 16:48
@FrozenPandaz FrozenPandaz enabled auto-merge (squash) March 20, 2026 16:48
@FrozenPandaz FrozenPandaz merged commit 2c4fb2a into master Mar 20, 2026
23 checks passed
@FrozenPandaz FrozenPandaz deleted the fix/34584-angular-rspack-mf-esm branch March 20, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants