Skip to content

Angular 21 + Nx Module Federation build fails on generated .federation/entry.*.js with sourceType: module parse error #34809

@cathypankova-fanka

Description

@cathypankova-fanka

Current Behavior

I am seeing a build failure in an Nx Angular workspace when building an Nx Module Federation remote.

The failure happens on the generated file inside node_modules/.federation/entry.*.js. That file contains an ESM import of @module-federation/webpack-bundler-runtime/dist/index.esm.js, but it is being processed by Angular’s webpack Babel loader and then fails with:

Module parse failed: 'import' and 'export' may appear only with 'sourceType: module'

Expected Behavior

I would expect to have a build in dist folder

GitHub Repo

No response

Steps to Reproduce

Steps I made to add a remote app to the existing nx monorepo:

npx nx g @nx/angular:host shell
npx nx g @nx/angular:remote mfeHello --host=shell
nx build mfeHello

Nx Report

Node           : 24.13.1
OS             : darwin-arm64
Native Target  : aarch64-macos
npm            : 11.8.0
daemon         : Disabled

nx (global)            : 22.5.0
nx                     : 22.5.4
@nx/js                 : 22.5.4
@nx/eslint             : 22.5.4
@nx/workspace          : 22.5.4
@nx/angular            : 22.5.4
@nx/devkit             : 22.5.4
@nx/eslint-plugin      : 22.5.4
@nx/module-federation  : 22.5.4
@nx/rspack             : 22.5.4
@nx/web                : 22.5.4
@nx/webpack            : 22.5.4
typescript             : 5.9.3
---------------------------------------
Community plugins:
@compodoc/compodoc : 1.2.1
angular-eslint     : 21.3.0
---------------------------------------
Cache Usage: 0.00 B / 46.04 GB

Failure Logs

./node_modules/.federation/entry.5361de3743f6650bd162336be6df2e54.js:1:0 - Error: Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' (1:0)

File was processed with these loaders:
 * ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js

You may need an additional loader to handle the result of these loaders.
> import federation from '/Users/katepankova/Documents/NSI/nsi-frontend/node_modules/@module-federation/webpack-bundler-runtime/dist/index.esm.js';
| if (!__webpack_require__.federation.runtime) {
|   var prevFederation = __webpack_require__.federation;

NX Ran target build for project mfeHello (26s)

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions