Module Federation on Node.js, Made Easy
Module Federation supports Node.js out of the box. Whether you are consuming modules at runtime only, or integrating into a Webpack/Rspack build pipeline, it can be adopted with a relatively small amount of configuration. This document walks through common ways to use Module Federation in Node.js.
Overview
In a Node.js server application, you can load remote modules via Module Federation. These modules can be local files built in CommonJS format, or remote services accessed over HTTP. This enables a flexible foundation for server-side microservices, dynamic feature delivery, and shared resources.
Consumer
Runtime-Only
If you are only consuming modules in Node.js and do not want to introduce bundlers like Webpack/Rspack, you can use the runtime-only approach. The key idea is: no build plugins required. You only need the APIs provided by @module-federation/runtime.
Steps:
- Create an MF instance with
createInstance. - Register remotes via the
remotesarray. - Load modules via
loadRemote.
The following example shows how to load a remote module exposed over HTTP:
Using a Bundler Plugin (Rspack/Webpack)
If your Node.js application is built with Webpack or Rspack, integrating Module Federation is straightforward: add the plugin and the required runtime configuration.
For the Host (consumer), the key is to add @module-federation/node/runtimePlugin and set remoteType: 'script' and target: 'async-node', then apply the rest of the configuration.
Rspack example (Webpack is largely the same):
After that, you can directly import remote modules in your code:
Provider
On the producer side, we recommend using Rslib. You only need to use the @module-federation/rsbuild-plugin plugin and set target: 'async-node' to generate a remote that can be consumed in Node.js.
Key configuration from apps/node-remote/rslib.config.ts:
If you are not using Rslib, you can also build the remote with Rspack/Webpack (the configuration is largely the same). The key points are: set target to async-node, and output remoteEntry.js with library.type = 'commonjs-module'.
Rspack example:
Webpack configuration is largely the same as the Rspack example above.
FAQ
1. What does target: 'async-node' do?
target: 'async-node' is a Webpack build target that produces output suitable for Node.js with asynchronous loading. This is important for Module Federation’s dynamic, async loading model—especially when you need top-level await while loading remotes.
2. Why do I need to set remoteType: 'script'?
Currently, the MF bundler runtime only supports the script remote loading type, so for Node.js consumption you need to explicitly set remoteType: 'script'.
References
- Host (Consumer) example config:
apps/node-host/webpack.config.js - Host (Consumer) example code:
apps/node-host/src/main.js - Remote (Producer) Rslib example config:
apps/node-remote/rslib.config.ts - Remote (Producer) Webpack example config:
apps/node-remote/webpack.config.js