Skip to content

Angular + Rspack + Module Federation: remoteEntry.js fails with "Unexpected token 'export'" due to missing experiments.outputModule #34584

@jdgarvey

Description

@jdgarvey

Hello! Ran into an issue generating a basic Angular + RSPack + Module Federation example.

Current Behavior

When generating an Angular Module Federation host + remote with --bundler=rspack, the remote's remoteEntry.js is emitted as ESM (with export statements) because NxModuleFederationPlugin sets library: { type: 'module' }. However, the generated rspack.config.ts does not set experiments.outputModule or output.module on the compiler, so the MF runtime loads the remote entry as a classic script, resulting in:

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

Expected Behavior

The generated config should produce working Module Federation out of the box. Either:

  1. NxModuleFederationPlugin should set experiments.outputModule = true and output.module = true on the compiler when it applies library: { type: 'module' }, or
  2. The @nx/angular:host and @nx/angular:remote generators should include these settings in the generated rspack.config.ts

GitHub Repo

https://github.com/jdgarvey/nx-angular-rspack-mf-esm-repro

Steps to Reproduce

npx create-nx-workspace@22.4.0 rspack-mf-repro --preset=angular-monorepo --style=scss --e2eTestRunner=none --bundler=rspack --ssr=false --interactive=false
cd rspack-mf-repro
npx nx g @nx/angular:host --directory=apps/shell --name=shell --bundler=rspack --dynamic=true --e2eTestRunner=none --ssr=false --skipTests=true --interactive=false
npx nx g @nx/angular:remote --directory=apps/remote --name=remote --bundler=rspack --host=shell --e2eTestRunner=none --ssr=false --skipTests=true --interactive=false
npx nx serve remote
# Open http://localhost:4200 → console shows "Unexpected token 'export'"

Workaround

Add the following to the webpackMerge call in both host and remote rspack.config.ts:

return webpackMerge(baseConfig[0], baseWebpackConfig, {
  experiments: { outputModule: true },
  output: { module: true, scriptType: 'module' },
});

Nx Report

  • Nx: 22.4.0
  • @nx/angular-rspack: 22.4.0
  • @nx/module-federation: 22.4.0
  • @rspack/core: 1.6.8
  • Angular: ~21.1.0 (resolved 21.1.5)
  • Node: 22.x
  • OS: macOS (arm64)

Thank you!

Metadata

Metadata

Assignees

Labels

communityThis is a good first issue for contributingpriority: highHigh Priority (important issues which affect many people severely)scope: module federationIssues related to module federation supporttype: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions