Webpack Module Federation with Angular 22
What you’ll learn
Section titled “What you’ll learn”- When webpack Module Federation is still the right choice for an Angular 22 project, and when it is not.
- What
@angular-architects/module-federation22 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.
Summary
Section titled “Summary”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.
The problem it solves
Section titled “The problem it solves”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.
How it works
Section titled “How it works”The package contributes three things:
- Schematics that rewrite
angular.jsonto use@angular-builders/custom-webpack:browserand@angular-builders/custom-webpack:dev-server, generatewebpack.config.jsandwebpack.prod.config.js, and splitmain.tsinto an asyncmain.tsplusbootstrap.ts. - 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. - A runtime, re-exported from
@angular-architects/module-federation(and implemented in@angular-architects/module-federation-runtime), withinitFederation,loadRemoteEntry,loadRemoteModule,loadManifestandsetManifest. Underneath, it builds on the Module Federation project’s@module-federation/enhanced2.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.
Add the package
Section titled “Add the package”npx ng add @angular-architects/module-federation@22 --project orders-mfe --port 4201 --type remote --stack module-federation-webpackOn 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] NoIn CI, or when the prompt cannot read the keyboard, install the package and run the schematic directly with --skip-confirmation:
npm install -D @angular-architects/module-federation@22npx ng g @angular-architects/module-federation:init-webpack --project orders-mfe --port 4201 --type remote --skip-confirmationThe 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.jsCREATE webpack.config.jsCREATE src/bootstrap.tsUPDATE tsconfig.jsonUPDATE tsconfig.app.jsonUPDATE angular.jsonUPDATE package.jsonUPDATE src/main.tsNote the licensing side effect: if your compliance process relies on 3rdpartylicenses.txt, you need another way to collect attributions.
Expose standalone routes from the remote
Section titled “Expose standalone routes from the remote”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.
Create a dynamic shell
Section titled “Create a dynamic shell”npx ng g @angular-architects/module-federation:init-webpack --project orders-portal --port 4200 --type dynamic-host --skip-confirmationA 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:
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.
Build output
Section titled “Build output”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).
Under the hood
Section titled “Under the hood”- The
sharedmap is passed to webpack’sModuleFederationPlugin.shareAllshares every dependency inpackage.json;singletonandstrictVersionfollow webpack’s semantics as documented in theModuleFederationPluginreference. 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’sremoteEntry.json, so on this path check the Angular versions in the remote’s lockfile instead. - The async
main.tsgives webpack a chance to negotiate shared versions before the first import of@angular/core. Bootstrapping directly inmain.tswith eager shared modules is the classic cause of “Shared module is not available for eager consumption” errors. loadRemoteEntrycan be called before bootstrapping to register a remote’s metadata early, so its shared versions take part in negotiation. With a manifest,initFederationdoes this for every listed remote.
Common mistakes
Section titled “Common mistakes”- Following a pre-22 tutorial’s builder setup. The current package uses
@angular-builders/custom-webpack. Runng update @angular-architects/module-federationwhen upgrading from 21. - Mixing Native Federation and webpack remotes in one manifest. They produce different artifacts (
remoteEntry.jsonplus import map versusremoteEntry.js) and different runtimes. Plan a migration per system rather than mixing them ad hoc. - Running
ng addin 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.
extractLicensesis turned off by the schematic.
When to use it and when not
Section titled “When to use it and when not”| 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) |
Compatibility
Section titled “Compatibility”@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.
Interview questions
Section titled “Interview questions”“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.
Key takeaways
Section titled “Key takeaways”- 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/enhanced2.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.
Related pages
Section titled “Related pages”Official references
Section titled “Official references”@angular-architects/module-federation22.0.0: npm and README@angular-builders/custom-webpack: npm- webpack 5: Module Federation concepts
- webpack 5:
ModuleFederationPluginreference - Angular v22: Custom build pipelines