npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@module-federation/node

v2.7.50

Published

Module Federation helper for Node

Readme

⚡ Features

  • Exposes two Webpack Plugins to enable Module Federation.
  • Can exported as UniversalFederationPlugin or NodeFederationPlugin with StreamingTargetPlugin
  • Allows server to fetch chunks across the network.
  • Allow distributed deployments of federated applications.

📦 Installation

To install the plugin run one of the following commands in your terminal for your application.

# npm
npm install @module-federation/node

# yarn
yarn add @module-federation/node

🚀 Usage

There are two approaches to using the plugins exported from this package, dependent on your use case.

Use as Runtime Plugin

module-federation/enhanced supports runtime plugins.

const { ModuleFederationPlugin } = require('@module-federation/enhanced');

const options = {
  target: 'async-node',
  output: {
    chunkFilename: '[id]-[contenthash].js', // important to hash chunks
  },
  plugins: [
    new ModuleFederationPlugin({
      name: 'app1',
      exposes: {},
      remotes: {
        app2: 'app2@http://',
      },
      runtimePlugins: [require.resolve('@module-federation/node/runtimePlugin')],
      remoteType: 'script',
      library: { type: 'commonjs-module', name: 'app1' },
    }),
  ],
};

or you can enable it with some presets via UniversalFederation

new UniversalFederationPlugin({
  name: 'website2',
  library: { type: 'commonjs-module' },
  isServer: true, // or false
  remotes: {},
  filename: 'remoteEntry.js',
  useRuntimePlugin: true, // uses the module-federation/enhanced runtime plugin api
  exposes: {
    './SharedComponent': './remoteServer/SharedComponent',
  },
});

UniversalFederationPlugin

This plugin is an abstraction over both NodeFederationPlugin and ModuleFederationPlugin. It will alternate between which it uses based on where the build is intended to be used.

If the build is intended to be used on the browser, it will use the standard ModuleFederationPlugin and bundle your code accordingly, however, if it is intended for server usage, it will use NodeFederationPlugin to create the bundle.

This simplifies the code required in your webpack.config.js to enable SSR Module Federation. It determines which platform it needs to build for based on two things:

  1. If the options passed to the plugin has specified isServer: true
  2. If the name assigned to the config being used is server

It accepts the other standard options from ModuleFederationPlugin as well. You can see an example usage below:

const { UniversalFederationPlugin } = require('@module-federation/node');

const config = {
  target: isServer ? false : 'web',
  plugins: [
    new UniversalFederationPlugin({
      name: 'website2',
      library: { type: 'commonjs-module' },
      isServer: true, // or false
      remotes: {},
      filename: 'remoteEntry.js',
      useRuntimePlugin: true, // uses the module-federation/enhanced runtime plugins
      exposes: {
        './SharedComponent': './remoteServer/SharedComponent',
      },
    }),
  ],
};

NodeFederationPlugin and StreamingTargetPlugin

You can also use each of the underlying plugins individually if you need more control over when they are used.

At build time, you need to be aware if you're building for the server or for the browser. If it's building for server, we need to set target: false to allow the plugins to function correctly.

The NodeFederationPlugin follows the same API as the Module Federation Plugin and therefore should be a drop-in replacement if you already have it set up in your webpack.config.js.

🔧 Config Example

An example configuration is presented below:

const { NodeFederationPlugin, StreamingTargetPlugin } = require('@module-federation/node');

const config = {
  target: isServer ? false : 'web',
  plugins: [
    new NodeFederationPlugin({
      name: 'website2',
      library: { type: 'commonjs-module' },
      remotes: {},
      filename: 'remoteEntry.js',
      exposes: {
        './SharedComponent': './remoteServer/SharedComponent',
      },
    }),
    new StreamingTargetPlugin({
      name: 'website2',
      library: { type: 'commonjs-module' },
      remotes: {},
    }),
  ],
};

Utilities

This package also exposes a few utilities to help with the setup of your federated application.

revalidate

Used to "hot reload" the federated application.

  • This is useful when you're developing your federated application and want to see changes without having to restart the server.
  • Also useful for production environments where you want to be able to update the federated application without having to restart the server.
import { revalidate } from '@module-federation/node/utils';

// we automatically reset require cache, so the reload callback is only if you need to do something else
revalidate().then((shouldReload) => {
  // do something extra after revalidation
  if (shouldReload) {
    // reload the server
  }
});

Note: To ensure that changes made to files in remotes are picked up revalidate, you can set the remotes webpack output.filename to [name]-[contenthash].js (or similar). This will cause the remoteEntry.js file to be regenerated with a unique hash every time a new build occurs. The revalidate method intelligently detects changes by comparing the hashes of the remoteEntry.js files. By incorporating [contenthash] into the remote's webpack configuration, you enable the shell to seamlessly incorporate the updated files from the remotes.

Hot reloading Express.js

Express has its own route stack, so reloading require cache will not be enough to reload the routes inside express.

//express.js
const app = express();

global.clearRoutes = () => {
  app._router.stack = app._router.stack.filter((k) => !(k && k.route && k.route.path));
};

// in some other file (within the scope of webpack build)
// wherever you have your revalidation logic
revalidate().then((shouldReload) => {
  if (shouldReload) {
    global.clearRoutes();
  }
});

Overriding default http chunk fetch

const chunkFetcher = globalThis.webpackChunkLoad || globalThis.fetch || fetchPolyfill;
// then it will pass one argument to the function, the url to fetch

chunkFetcher(url)
  .then((res) => res.text())
  .then((text) => {
    // do something with the text
  });

If you want to use your own custom fetch, or add fetch headers, either in the entrypoint of webpack or outside of webpack scope, like in express server you can override the default chunk fetcher by setting the globalThis.webpackChunkLoad variable.

globalThis.webpackChunkLoad = async (url) => {
  const res = await fetch(url, {
    headers: {
      'x-custom-header': 'custom-header-value',
    },
  });
  return res.text();
};

🔑 License

👨‍💻 Contributors

List of our amazing contributors 💥