# Module Federation

Each team builds and deploys its own bundle. The shell loads those bundles at runtime and can share common dependencies, such as React, as a single copy.

## How it works

1. **Shell loads.** The browser loads the shell, which knows where each remote's entry file lives.
2. **Fetch the remote entry.** When a slot is needed, the shell requests team A's remote entry and the chunks it points to.
3. **Share dependencies.** Shared modules come from a common share scope. With a singleton, everyone uses one copy and a version mismatch prints a warning.
4. **Mount.** Team A's module renders into its slot. Team B loads the same way, from its own deployment.

## Try it

**Demo: Shared dependency conflict.**

Team A and Team B both use React, and both start on 18.3, so the browser downloads one shared copy and both apps render. Move Team B to React 19.0 and the two versions no longer share a major version. With no singleton, each app brings its own copy: everything works, but users download a second React, about 45 KB more, and a component from one copy can't render inside the other copy's tree or read its context. Force a singleton instead and only the higher version, 19.0, is loaded, so Team A, built for 18.3, runs on a React it wasn't built for and may break. In Module Federation a singleton version mismatch only prints a warning, and with strictVersion it is a runtime error. Native Federation uses the shared copy silently, and with strictVersion gives that team its own copy instead, so the forced singleton no longer holds. The sizes are illustrative.

Takeaway: Dependency sharing is a real cost. Either teams coordinate versions, or users download duplicates, or a forced singleton breaks someone at runtime. Pick one on purpose.

## Pros

- Teams deploy their remotes independently; the shell picks up new versions at runtime.
- Shared dependencies can be loaded once instead of once per team.
- Remote modules load on demand, when a slot needs them.

## Cons

- Version mismatches in shared dependencies show up at runtime, not at build time.
- More moving parts: remote URLs per environment and fallbacks for remotes that fail to load.
- Extra network requests when a remote first loads.

## Best when

- Several teams on the same framework.
- Teams regularly blocked by a shared release.
- CI/CD and monitoring mature enough to own runtime failures.

## Avoid when

- One or two teams.
- Strict performance budgets without a plan for preloading.
- Domain boundaries that are still unclear.

## In code

`webpack.config.js · shell/src/bootstrap.js`

```js
// webpack.config.js, in plugins: the shell declares where team A's build lives
new ModuleFederationPlugin({
  name: "shell",
  remotes: {
    teamA: "teamA@https://team-a.example.com/remoteEntry.js",
  },
  shared: { react: { singleton: true } },
});

// shell/src/bootstrap.js, at runtime: load team A's exposed module and mount it
async function mountTeamA() {
  const { mount } = await import("teamA/App");
  mount(document.querySelector("#team-a"));
}
```

## Ratings

_Editorial judgement for a typical team, from 1 to 5._

- **Team independence: 4/5** (higher is better). Each remote is a separate build that deploys on its own; the shell loads whatever is deployed at runtime.
- **Runtime performance: 3/5** (higher is better). Each remote adds requests when it loads, while shared singletons avoid downloading the same library twice.
- **Complexity: 4/5** (lower is simpler). You negotiate shared versions, manage remote URLs per environment, and handle remotes that fail to load.
- **SSR / SEO support: 3/5** (higher is better). Server rendering is possible but needs extra setup beyond the client-side loading the docs describe.
- **Tech-agnostic: 2/5** (higher is better). Mixing frameworks is technically possible, but sharing works best when every build uses the same framework.
- **Isolation: 2/5** (higher is better). Remotes run in the same page and share globals, styles and the share scope.
- **UX consistency: 4/5** (higher is better). Remotes render into one page and can share a design system as a shared dependency.
- **Tooling maturity: 4/5** (higher is better). Built into webpack and supported by Rspack and a Vite plugin, with a dedicated project that adds a runtime, manifest and devtools.

## Tooling and ecosystem

Module Federation is built into webpack 5 as `ModuleFederationPlugin`. The [Module Federation project](https://module-federation.io/guide/start/index.html) maintains Module Federation 2.0, which adds a federation runtime, a manifest (`mf-manifest.json`), dynamic type hints, a runtime plugin system and Chrome DevTools support; its introduction lists Rspack and webpack as supported build tools. The project also documents a [Vite integration](https://module-federation.io/integrations/build-tool/vite.html), `@module-federation/vite` (1.23 as of November 2026). Its Next.js plugin, `@module-federation/nextjs-mf`, has been in maintenance mode since November 2024: the core team does no new development on it and expects to stop tracking it in the second half of 2026 ([module-federation/core#3153](https://github.com/module-federation/core/issues/3153)).

In webpack's shared configuration, `singleton: true` keeps one copy of a library such as React and prints a warning when the chosen version doesn't satisfy a consumer's `requiredVersion`; adding `strictVersion: true` turns that warning into a runtime error.

## Sources

- [Module Federation](https://webpack.js.org/concepts/module-federation/), webpack documentation
- [ModuleFederationPlugin](https://webpack.js.org/plugins/module-federation-plugin/), webpack documentation
- [Module Federation — Introduction](https://module-federation.io/guide/start/index.html), module-federation.io
- [Vite — Module Federation integrations](https://module-federation.io/integrations/build-tool/vite.html), module-federation.io
- [Next.js Support is in maintenance mode (issue](https://github.com/module-federation/core/issues/3153), Zack Jackson · GitHub, module-federation/core

https://microfrontends.dev/approaches/module-federation