Micro-Frontend Architectures at Scale: Module Federation with Vite, Version Mismatches, and Shared Dependencies
How to decouple enterprise frontend applications: runtime script federation, singleton dependency negotiation, and shared state across independent deployments.
As engineering organizations scale beyond dozens of autonomous teams, monolithic frontend repositories become development bottlenecks. Micro-frontends decompose large web applications into independently developed, tested, and deployed micro-applications. Module Federation enables these independent micro-applications to share runtime dependencies (like React or UI design systems) and load remote components on-demand without iframes or multi-page refreshes.
THE PRODUCTION PROBLEM STATEMENT
Early micro-frontends relied on iframes (which break responsive layouts, accessibility, and deep routing) or npm package distribution (which requires re-building and re-deploying the entire host shell whenever an internal package updates).
How Does Module Federation Resolve Remote Components at Runtime?
A host application declares remotes in its configuration. At runtime, the browser fetches remoteEntry.js-a lightweight manifest containing the remote application’s export mappings and shared dependency versions.
Module Federation’s share scope negotiates semver versions of common libraries (such as react and react-dom). If both host and remote declare compatible versions, the browser downloads React exactly once, preventing duplicate runtime instances.
// vite.config.ts (Host Shell Application)
import { defineConfig } from 'vite';
import federation from '@originjs/vite-plugin-federation';
export default defineConfig({
plugins: [
federation({
name: 'host-app',
remotes: {
// Loads remote checkout app dynamically at runtime
checkoutApp: 'https://checkout.domain.com/assets/remoteEntry.js'
},
shared: {
react: { singleton: true, requiredVersion: '^18.3.0' },
'react-dom': { singleton: true, requiredVersion: '^18.3.0' }
}
})
]
});
// Consuming remote component in Host React view:
import React, { Suspense } from 'react';
const RemoteCheckout = React.lazy(() => import('checkoutApp/Checkout'));
export function CartPage() {
return (
<Suspense fallback={<div>Loading Secure Checkout Module...</div>}>
<RemoteCheckout cartId="cart-902" />
</Suspense>
);
}Why Are Singleton Dependencies Essential for React?
React relies on module-scoped singleton state (e.g. ReactCurrentDispatcher in React Fiber). If the host loads React 18.2 and a remote inadvertently downloads React 18.3, hooks break with "Invalid hook call: Hooks can only be called inside the body of a function component".
Marking react and react-dom with singleton: true forces Module Federation to reuse the host instance, resolving semver conflicts safely.
<!-- Anti-Pattern: Breaks deep linking, accessibility, modals, and responsive layout -->
<iframe src="https://checkout.domain.com" class="w-full h-[600px]" />// Recommended: Native DOM integration with shared React context
const RemoteCheckout = React.lazy(() => import('checkoutApp/Checkout'));
<Suspense fallback={<CheckoutSkeleton />}>
<RemoteCheckout />
</Suspense>[PROBABLE CAUSE] Attempted to synchronously import a shared singleton library in entry index.ts before the federation initialization handshake completed.
[VERIFIED RESOLUTION] Create an async bootstrap boundary: in index.ts, call import("./bootstrap") and move application bootstrap code into bootstrap.ts.
// index.ts: import('./bootstrap');Frequently Asked Questions & Technical Inquiries
Direct, practical answers to common architectural and debugging questions.
Yes! The @originjs/vite-plugin-federation plugin generates manifests and chunk loaders compatible with Webpack 5 Module Federation specifications.
Faisal Askari
Verified AuthorSoftware Engineer & Full-Stack Developer
Faisal Askari is a software engineer with deep expertise in web systems architecture, the JavaScript runtime ecosystem, and client-side performance engineering. Over years of hands-on production engineering, he has designed and shipped enterprise dashboards, high-converting digital interfaces, and specialized full-stack applications.
Enterprise Frontend Architecture & Scale
Transitioning a complex frontend monolithic app to high-velocity autonomous micro-frontends?
The Modern Web Build Pipeline: Decoupling Bundling, Transpilation, and Hot Module Replacement
How modern frontend toolchains evolved from monolithic webpack bundling to native ESM dev servers, Go-compiled transpilation, and optimal production chunking.
Architectural Blueprint for Modern Business Websites: Speed, SEO, and Conversion Engineering
How to structure multi-page web platforms that achieve perfect Lighthouse scores, rank on search engines, and convert visitors into qualified business inquiries.