Skip to content

Webpack Module Federation with Angular 22

  • When webpack Module Federation is still the right choice for an Angular 22 project, and when it is not.
  • What @angular-architects/module-federation 22 changes in your workspace, including its new webpack builder.
  • How to expose standalone routes from a webpack remote and load them from a shell through mf.manifest.json.
  • How this path differs from the Native Federation setup used in the rest of this section.

webpack Module Federation is a webpack feature: a build produces a container (remoteEntry.js) that other webpack builds can load at runtime, with negotiated shared dependencies. Angular’s CLI no longer builds new applications with webpack; it uses the esbuild-based application builder. To use webpack Module Federation with Angular 22 you therefore swap the project back to a webpack builder, which @angular-architects/module-federation 22.0.0 does for you through @angular-builders/custom-webpack.

This section recommends Native Federation for new Angular 22 systems. The webpack path is for joining or extending an existing Module Federation system, for example a shell that already loads remotes built with webpack or Rspack in other frameworks. The package’s own ng add warns about this when run against an esbuild project. Versions for both paths are listed once in Prerequisites.

Suppose a company already runs a webpack-based portal shell that loads three remotes through remoteEntry.js files, two in React and one in an older Angular version. A new Angular 22 team must plug the orders area into that shell. Native Federation produces remoteEntry.json plus an import map, which the existing webpack shell does not understand. Building the new remote with webpack Module Federation lets it speak the same container protocol as everything else.

The reverse also happens: an Angular shell built years ago with @angular-architects/module-federation must be upgraded to Angular 22 without migrating every remote to Native Federation in the same release. Staying on webpack Module Federation for now, and planning the migration separately, keeps the upgrade small.

The package contributes three things:

  1. Schematics that rewrite angular.json to use @angular-builders/custom-webpack:browser and @angular-builders/custom-webpack:dev-server, generate webpack.config.js and webpack.prod.config.js, and split main.ts into an async main.ts plus bootstrap.ts.
  2. A config helper, withModuleFederationPlugin, imported from @angular-architects/module-federation/webpack. Your config is a partial webpack configuration that contains only federation settings; the CLI generates everything else.
  3. A runtime, re-exported from @angular-architects/module-federation (and implemented in @angular-architects/module-federation-runtime), with initFederation, loadRemoteEntry, loadRemoteModule, loadManifest and setManifest. Underneath, it builds on the Module Federation project’s @module-federation/enhanced 2.x runtime (2.9.3 is current on npm), the same runtime webpack and Rspack builds use.

Up to and including Angular 21 the package used ngx-build-plus to inject the webpack config. From Angular 22 it uses @angular-builders/custom-webpack; ng update @angular-architects/module-federation migrates existing workspaces. Tutorials that install ngx-build-plus for Angular 22 are out of date.

The package also offers an experimental Rspack option. Its init schematic accepts --stack module-federation-webpack or --stack module-federation-rsbuild-experimental, and its README credits @nx/angular-rspack for the Rspack integration. Treat Rspack as experimental unless the package documentation for your version says otherwise.

Realistic example: a webpack remote and shell

Section titled “Realistic example: a webpack remote and shell”

The commands below were run with Angular CLI 22.2.7, @angular-architects/module-federation 22.0.0 and @angular-builders/custom-webpack 22.x on Node.js 22.23. Both builds succeeded and the shell rendered the remote’s routes in headless Chrome.

Terminal window
npx ng add @angular-architects/module-federation@22 --project orders-mfe --port 4201 --type remote --stack module-federation-webpack

On an esbuild-based project, ng add stops and asks for confirmation:

WARNING: This package uses the traditional webpack-based Module Federation implementation and not the fast new esbuild-based ApplicationBuilder.
For new projects, consider Native Federation as an alternative: https://github.com/native-federation
However, if you want to add a new host or remote to an existing Module Federation-based system, this package is what you are looking for.
Do you want to proceeed: [y] Yes [n] No

In CI, or when the prompt cannot read the keyboard, install the package and run the schematic directly with --skip-confirmation:

Terminal window
npm install -D @angular-architects/module-federation@22
npx ng g @angular-architects/module-federation:init-webpack --project orders-mfe --port 4201 --type remote --skip-confirmation

The schematic’s --type accepts host, dynamic-host, remote or legacy. It reports:

Switching to webpack
[INFO] extractLicenses has been turned off: license-webpack-plugin cannot
[INFO] read Module Federation's container modules and fails the build.
[INFO] Production builds will no longer emit 3rdpartylicenses.txt, so
[INFO] collect third-party attributions another way if you rely on it.
CREATE webpack.prod.config.js
CREATE webpack.config.js
CREATE src/bootstrap.ts
UPDATE tsconfig.json
UPDATE tsconfig.app.json
UPDATE angular.json
UPDATE package.json
UPDATE src/main.ts

Note the licensing side effect: if your compliance process relies on 3rdpartylicenses.txt, you need another way to collect attributions.

Edit the generated webpack.config.js:

const {
shareAll,
withModuleFederationPlugin,
} = require('@angular-architects/module-federation/webpack');
module.exports = withModuleFederationPlugin({
name: 'ordersMfe',
exposes: {
'./routes': './projects/orders-mfe/src/app/orders/orders.routes.ts',
},
shared: {
...shareAll({ singleton: true, strictVersion: true, requiredVersion: 'auto' }),
},
});

The routes file is the same standalone ORDERS_ROUTES shown in Remote configuration; nothing about the Angular code depends on which federation tool builds it. webpack container names become JavaScript identifiers, which is why the example uses ordersMfe rather than a hyphenated name.

Terminal window
npx ng g @angular-architects/module-federation:init-webpack --project orders-portal --port 4200 --type dynamic-host --skip-confirmation

A dynamic host gets public/mf.manifest.json and a main.ts that loads it before bootstrapping:

// src/main.ts (generated)
import { initFederation } from '@angular-architects/module-federation';
initFederation('mf.manifest.json')
.catch((err) => console.error(err))
.then((_) => import('./bootstrap'))
.catch((err) => console.error(err));
{ "ordersMfe": "http://localhost:4201/remoteEntry.js" }

Load the remote’s routes by manifest key:

src/app/app.routes.ts
import { Routes } from '@angular/router';
import { loadRemoteModule } from '@angular-architects/module-federation';
export const routes: Routes = [
{
path: 'orders',
loadChildren: () =>
loadRemoteModule({ type: 'manifest', remoteName: 'ordersMfe', exposedModule: './routes' })
.then((m) => m.ORDERS_ROUTES),
},
];

The runtime also accepts { type: 'module', remoteEntry: 'https://orders.example.test/remoteEntry.js', exposedModule: './routes' } when you want to pass a URL directly. Add the same .catch fallback as in Host application setup; failure handling does not change between the two tools.

Unlike the esbuild builder, the webpack builder writes directly to dist/<project>/ without a browser/ subfolder. The remote’s output contains remoteEntry.js; the shell’s contains mf.manifest.json. The generated dev-server target already sends Access-Control-Allow-Origin: * on the remote’s port; production hosting needs its own CORS configuration, as described in Azure deployment (use dist/<project> as the deploy folder).

  • The shared map is passed to webpack’s ModuleFederationPlugin. shareAll shares every dependency in package.json; singleton and strictVersion follow webpack’s semantics as documented in the ModuleFederationPlugin reference. The Native Federation runtime behavior shown in Advanced concepts is not evidence for this path, so rehearse a version skew here separately. A pre-deployment version check belongs in the remote’s pipeline on both paths; the script in Azure deployment reads Native Federation’s remoteEntry.json, so on this path check the Angular versions in the remote’s lockfile instead.
  • The async main.ts gives webpack a chance to negotiate shared versions before the first import of @angular/core. Bootstrapping directly in main.ts with eager shared modules is the classic cause of “Shared module is not available for eager consumption” errors.
  • loadRemoteEntry can be called before bootstrapping to register a remote’s metadata early, so its shared versions take part in negotiation. With a manifest, initFederation does this for every listed remote.
  • Following a pre-22 tutorial’s builder setup. The current package uses @angular-builders/custom-webpack. Run ng update @angular-architects/module-federation when upgrading from 21.
  • Mixing Native Federation and webpack remotes in one manifest. They produce different artifacts (remoteEntry.json plus import map versus remoteEntry.js) and different runtimes. Plan a migration per system rather than mixing them ad hoc.
  • Running ng add in CI without --skip-confirmation. The confirmation prompt needs an interactive terminal and fails otherwise.
  • Expecting esbuild build times. The webpack builder is slower; measure before committing a large workspace to it.
  • Forgetting the license file change. extractLicenses is turned off by the schematic.
Situation Recommendation
New Angular 22 shell and remotes Native Federation
Adding an Angular remote to an existing webpack/Rspack Module Federation shell webpack Module Federation
Upgrading an existing Angular Module Federation system to 22 Stay on webpack MF for the upgrade, plan a separate migration
Need the esbuild builder’s speed, SSR or hydration with federation Native Federation
Mixed frameworks loaded through one Module Federation runtime webpack Module Federation (or web components on either path)

@angular-architects/module-federation publishes one major per Angular major: 22.x for Angular 22, 21.2.x for Angular 21, and so on, as listed in its README. Its runtime package, @angular-architects/module-federation-runtime 22.0.0, declares peer dependencies on @angular/core and @angular/common ^22.0.0 and on @module-federation/enhanced and @module-federation/runtime-core ^2.2.2.

“Our portal shell is webpack-based and loads React and Vue remotes. A new Angular 22 team joins. Native Federation or webpack Module Federation?” webpack Module Federation for this remote: the shell understands only remoteEntry.js containers, and a Native Federation remote produces remoteEntry.json plus an import map. Accept the slower webpack builder for that project, and keep the Angular code (standalone routes, fallbacks) tool-neutral so a later migration is cheap.

“We are upgrading an Angular 20 Module Federation estate to 22. Should we switch to Native Federation in the same project?” No. Do the Angular upgrade on the webpack path with ng update, which also migrates the builder, and ship it. Switching federation tools changes every remote’s build and the shell’s runtime at once; as a separate project it can be done remote by remote behind a stable contract.

“Can one shell load both Native Federation and webpack remotes?” Not through one manifest: the artifacts and runtimes differ. Where it is unavoidable, load the odd remote as a web component with its own runtime and treat it as a temporary bridge with an end date, because it duplicates framework code and loses the shared injector.

“Compliance says the production build no longer contains 3rdpartylicenses.txt. Why?” The webpack Module Federation schematic turns extractLicenses off, because the license plugin cannot read Module Federation’s container modules. Collect attributions another way (for example a license scanner in CI) rather than turning it back on and breaking the build.

  • webpack Module Federation is a webpack feature integrated by community packages; it is not part of Angular.
  • In Angular 22 it runs through @angular-builders/custom-webpack, and its runtime is @module-federation/enhanced 2.x.
  • Choose it to join an existing Module Federation estate; choose Native Federation for new Angular systems.
  • Your Angular code (standalone routes, fallbacks, contracts) is the same on both paths; only the build and runtime differ.