Registry / devops / webpack-plugin-module-federation

webpack-plugin-module-federation

JSON →
library1.0.0-beta-1jsnpmunverified

A Webpack 4 plugin that implements module federation, allowing multiple separately built applications to share code and dependencies at runtime. This is an early beta (v1.0.0-beta-1) of the official ModuleFederationPlugin backported for Webpack 4, with similar API to the Webpack 5 version. It enables micro-frontends by exposing and consuming remote modules via a dynamic import pattern. Unlike the Webpack 5 built-in, this requires explicit configuration of libraryTarget 'global' and manual addition of remoteEntry.js scripts to HTML. The library is considered experimental, not recommended for production, and lacks the maturity and features of the official Webpack 5 ModuleFederationPlugin.

npm install webpack-plugin-module-federation
INSTALL
IMPORT
SIG · WEBPACK-PLUGIN-MOD
W
webpack-plugin-module-federation
devopsjavascriptv1.0.0-beta-1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

moduleFederationPlugin
const moduleFederationPlugin = require('webpack-plugin-module-federation');
import moduleFederationPlugin from 'webpack-plugin-module-federation';
This package does not export ESM. Use CommonJS require. No default export.
ModuleFederationPlugin
const { ModuleFederationPlugin } = require('webpack-plugin-module-federation');
const ModuleFederationPlugin = require('webpack-plugin-module-federation').ModuleFederationPlugin;
Named export, not default. Also available as the whole module's default? The README uses require directly as moduleFederationPlugin, but the internal new ModuleFederationPlugin suggests it's a constructor.
moduleFederationPlugin
new (require('webpack-plugin-module-federation'))({...})
new require('webpack-plugin-module-federation').ModuleFederationPlugin({...})
The package exports a constructor function directly. Use new require(...)() or assign to a variable. The README example incorrectly nests new ModuleFederationPlugin inside new moduleFederationPlugin.

Webpack 4 configuration to expose a remote entry point for module federation. Requires setting libraryTarget to 'global' and manually including remoteEntry.js script in host HTML.

const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const ModuleFederationPlugin = require('webpack-plugin-module-federation'); module.exports = { entry: './src/index', mode: 'development', devServer: { port: 3001, hot: true }, output: { publicPath: 'http://localhost:3001/', }, plugins: [ new ModuleFederationPlugin({ name: '_federation_app1', library: 'app1', filename: 'remoteEntry.js', libraryTarget: 'global', remotes: { app2: 'app2', }, exposes: { App: './src/App', }, }), new HtmlWebpackPlugin({ template: './public/index.html' }), ], };
Debug
Known issues
breakingThe package is in beta (v1.0.0-beta-1) and may introduce breaking changes without notice.
fix
Consider using Webpack 5 with built-in ModuleFederationPlugin for stable API.
affects: =1.0.0-beta-1
gotchaThe configuration example in README has a nested new ModuleFederationPlugin inside new moduleFederationPlugin incorrectly. Correct usage is directly new moduleFederationPlugin(options) with ModuleFederationPlugin options.
fix
Use: const MFPlugin = require('webpack-plugin-module-federation'); new MFPlugin({...})
affects: >=0.0.0
gotchaYou must set libraryTarget to 'global' and manually add <script src="http://remotPath/remoteEntry.js"></script> to your HTML for remote consumption to work.
fix
Set output.publicPath appropriately and add script tag referencing the remoteEntry.js file.
affects: >=0.0.0
gotchaDynamic imports from remotes use strings like 'website2/Title' which depend on the 'expose' configuration key matching in both host and remote.
fix
Ensure expose keys match exactly and the remote container is loaded before dynamic import.
affects: >=0.0.0
deprecatedThis package is a backport for Webpack 4. The official ModuleFederationPlugin is only available in Webpack 5. This package is no longer maintained.
fix
Migrate to Webpack 5 and use its built-in ModuleFederationPlugin.
affects: >=0.0.0
Errors
Common errors & fixes
Error: ModuleFederationPlugin is not a constructor
Using new ModuleFederationPlugin({...}) instead of new moduleFederationPlugin({...}) incorrectly.
fix
Use: const MFPlugin = require('webpack-plugin-module-federation'); new MFPlugin({...});
Cannot find module 'webpack-plugin-module-federation'
Missing npm install of the package.
fix
Run: npm install --save-dev webpack-plugin-module-federation
Uncaught SyntaxError: Unexpected token 'export'
Attempting to use ES6 import syntax with CommonJS require in Node.js.
fix
Use require instead: const MFPlugin = require('webpack-plugin-module-federation');
remoteEntry.js:1 Uncaught ReferenceError: module is not defined
Using libraryTarget: 'var' or 'commonjs' incorrectly; this plugin requires 'global'.
fix
Set libraryTarget: 'global' in ModuleFederationPlugin options.
Upgrade
Version history
1.0.0-beta-1latest on npm
Audit
Dependencies
webpackrequiredPeer dependency; requires Webpack 4.x.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
2
Resources
webpack-plugin-module-federation — npm install webpack-plugin-module-federation · libregistry