next-federation
API Reference

@next-federation/vite

Vite 8 plugins that build an island remote (nextFederationIslands) or a remote components build (nextFederationComponents). Requires Node ^20.19.0 ||...

Vite 8 plugins that build an island remote (nextFederationIslands) or a remote components build (nextFederationComponents). Requires Node ^20.19.0 || >=22.12.0. The island plugin wraps @vitejs/plugin-rsc, pinned to exactly 0.5.39 (NF-025 otherwise).

Install

npm install --save-exact react@19.3.1 react-dom@19.3.1 react-server-dom-webpack@19.3.1
npm install -D @next-federation/vite @next-federation/server vite

react-server-dom-webpack must match your React version exactly and be a patched release (NF-041). A components remote does not need it. See Writing an island remote.

nextFederationIslands(options)

Returns the Vite plugin array for an island remote. An island entry is a Server Component with a default export and no 'use client' (NF-002).

vite.config.ts
import { nextFederationIslands } from '@next-federation/vite'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: nextFederationIslands({
    name: 'shop',
    base: 'https://shop.example.com/',
    hosts: ['https://www.example.com'],
    issuers: { 'https://www.example.com': 'https://www.example.com/api/next-federation/jwks' },
    islands: {
      ProductPanel: './src/islands/ProductPanel.tsx',
      MyOrders: { entry: './src/islands/MyOrders.tsx', private: true },
    },
  }),
})

vite build writes dist/<buildId>/{client,ssr,rsc} and nf-build.json. Serve it with nf-serve --dir dist --port <port> from @next-federation/server.

OptionTypeDefaultDescription
namestringrequiredRemote id. Matches ^[A-Za-z][A-Za-z0-9_-]*$.
basestringrequiredAbsolute URL the remote is served from (NF-020 if relative).
islandsRecord<string, string | { entry: string; private?: boolean }>requiredIslands to build. private: true requires a verified token.
hostsstring[]requiredExact host origins allowed to embed the remote. No '*'.
issuersRecord<string, string>noneIssuer to JWKS URL map for identity verification.
buildIdstringNF_BUILD_ID, then 'dev' or a timestampMatches ^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$.
versionedbooleantrue for build, false for servePin assets under <base>b/<buildId>/.
maxAgenumber60Public island max-age, in seconds.
outDirstring'dist'Output folder.
shareboolean | { libs?: string[] }true for build, false for serveShare React with other island remotes. libs adds specifiers.
allowInsecureHttpbooleanfalseAccept plain-http base or JWKS URL in production. Warns.
actions{ requireIdentity?, maxBodyBytes?, timeoutMs? }noneServer Action settings (below).
actions optionTypeDefaultDescription
requireIdentitybooleanfalseEvery Server Action needs a verified token (401 NF-014).
maxBodyBytesnumber1048576Server Action body limit.
timeoutMsnumbernoneBrowser aborts a slow call and rejects with NF-038. The action may run.

base and JWKS URLs must use https, except for loopback hosts, serve, or NODE_ENV of development or test.

nextFederationComponents(options)

Returns the Vite plugins for a components remote. It wraps @module-federation/vite, pinned to exactly 1.24.0 (NF-026 otherwise; NF_ALLOW_MF_VITE=1 for a canary job).

vite.config.ts
import { nextFederationComponents } from '@next-federation/vite'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    nextFederationComponents({
      name: 'shop',
      base: 'https://shop.example.com/',
      exposes: { './Cart': './src/Cart.tsx' },
      shared: { '@acme/date-utils': { requiredVersion: '^2.0.0', fallback: true } },
    }),
  ],
})
OptionTypeDefaultDescription
namestringrequiredModule Federation container name. A JavaScript identifier.
basestringrequiredAbsolute URL the remote is served from.
exposesRecord<string, string>requiredExposed modules, such as { './Cart': './src/Cart.tsx' }.
sharedstring[] | Record<string, SharedModuleOptions>noneModules the host provides, besides React.
reactstring'^19.0.0'Accepted React range. A host outside it renders its fallback (NF-036).
linksbooleantrueRoute the remote's links through the host's router.
buildIdstringsee islandsThe build id.
outDirstring'dist'Output folder. Builds go to <outDir>/<buildId>.
ssrbooleantrueBuild the CommonJS server copy hosts render on the server.
allowInsecureHttpbooleanfalseAccept plain-http base in a production build. Warns.
typesbooleanfalseEmit signed declarations into client/@mf-types/ for nf-types.

SharedModuleOptions takes requiredVersion (semver range the host copy must satisfy) and fallback (bundle this build's own copy). react, react-dom and next cannot set fallback: true (NF-002).

  • vite build writes client/ and the server copy, nf-components.json (signed with ES256 when NF_COMPONENTS_SIGNING_KEY holds a private JWK) and nf-build.json.
  • The dev server answers /_nf/components.json with ssr: null, so dev remotes render in the browser only.
  • types: true needs TypeScript 5 or 6 and publishes declarations of exposed modules and their local imports. Do not expose a module whose types reach a secret.
  • Programmatic builds set NF_VITE_COMMAND=build.

See Links that work in every host and Keeping a standalone app.

resolveOptions(options, ctx)

Validates the island options (NF-020 for a relative base, NF-002 otherwise) and returns the resolved shape. ctx is { command, env, now }.

Types

IslandRemoteOptions, ResolveContext, ResolvedOptions, BuildInfo ({ name, buildId, builtAt, base }), ComponentsRemoteOptions, SharedModuleOptions and ComponentsBuildInfo (kind: 'components').

Build behaviour

Details are in Writing an island remote and Limits. Not covered there:

  • The page-wide share scope is __FEDERATION__.__SHARE__['@next-federation/island-share@1']['nf-islands']. react-server-dom-webpack is never shareable (NF-002).
  • server.forwardConsole is false unless your config sets it.
  • Dev CORS: Vite's CORS middleware is off. Assets get CORS for hosts only.

Learn more

License: MIT

On this page