This project is the host app for a Next.js Module Federation setup using @module-federation/nextjs-mf.
The host loads one role-selected remote application:
remote1/DashboardShell(customer)remote2/DashboardShell(admin)
These rules are mandatory for this app:
- Node.js: Use only Node 18 or 20 (LTS).
- Next.js version: Keep Next.js at 15.x. Do not upgrade beyond v15.
- React version: Keep React and ReactDOM on 18.x (current setup:
18.2.0) and keep both versions aligned. - Bundler mode: Use Webpack mode only (no Turbopack). Keep
NEXT_PRIVATE_LOCAL_WEBPACK=truein scripts. - Routing system: Keep this app on the Pages Router. Do not migrate this app to App Router.
- Federation sharing: Configure shared packages correctly (especially React/ReactDOM as singletons) to avoid duplicate runtimes.
- Remote contract discipline: Version remote changes carefully and keep host/remote APIs backward-compatible.
- Failure handling: Always provide fallback UI/error handling when a remote fails to load.
Current baseline in this app:
next:15.3.8react:18.2.0react-dom:18.2.0@module-federation/nextjs-mf:^8.8.56
- Install dependencies:
npm installThis app installs @dasjideepak/* packages from GitHub Packages and requires auth.
Create a Personal Access Token (classic):
- GitHub ->
Settings->Developer settings->Personal access tokens->Tokens (classic) - Click
Generate new token (classic) - Select scopes:
read:packages(required to install private packages)repo(required when package/repository is private)write:packages(only needed for publishing)
- Copy and store the token securely.
This repo expects:
GITHUB_PACKAGES_TOKEN
This app's .npmrc uses it:
@dasjideepak:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}Set token before install:
export GITHUB_PACKAGES_TOKEN=ghp_xxx_your_token_here
npm installIn Vercel project settings for host:
- Go to
Settings->Environment Variables - Add
GITHUB_PACKAGES_TOKEN - Apply to
Production,Preview, andDevelopmentas needed - Redeploy to apply changes
- Never commit tokens to Git.
- Rotate token immediately if exposed.
- Use least privilege (
read:packages+repofor consumers).
-
Make sure both remote apps are running on
3001and3002. -
Start the host:
npm run dev- Open:
http://localhost:3000
npm run dev- run development server with local webpack federation support.npm run build- create production build with federation support.npm run start- run production server.npm run lint- run ESLint.
Federation is configured in next.config.ts:
- Host name:
host - Remote entry output:
static/chunks/remoteEntry.js - Remote entries:
remote1@http://localhost:3001/_next/static/{ssr|chunks}/remoteEntry.jsremote2@http://localhost:3002/_next/static/{ssr|chunks}/remoteEntry.js
The host page imports remotes dynamically in src/pages/index.tsx with ssr: false.