Metro (React Native)
Deploy your React Native applications with Module Federation to Zephyr Cloud using Metro bundler. The Zephyr Metro plugin integrates seamlessly with Metro's build process and enables micro-frontend architectures for React Native applications.
- Finished our Prerequisites setup guide
- Installed our Chrome extension
- npm >=10
- node >=18
- ruby >= 3.3.2
- React 19 and React Native 0.79 or newer
This detects your bundler and configures Zephyr automatically. Learn more →
For manual setup, continue below.
Installation
Install the Metro plugin and required Module Federation dependencies in your project:
The bundle-mf-host and bundle-mf-remote publication commands require React 19, React Native 0.79 or newer, @module-federation/metro@^2.9.0, @babel/types >=7.25.0 <8.0.0, and metro, metro-config, metro-file-map, metro-resolver, and metro-source-map at >=0.82.1 <0.83.0. The configuration-only withZephyr() wrapper does not need these minimums.
To enable React Native OTA updates in a host app, also install the native cache runtime:
Configuration and Publication
Metro configuration and publication are separate stages:
Loading withZephyr() can request /application-config and /build-id, but those requests do not persist an organization membership, project, application, or application version. Publication reaches /build-stats; the first successful upload creates the dashboard entities for that application identity. A token claim of can_write: true grants permission to create that identity. It does not mean the records already exist.
You must register the publication commands through either the React Native CLI configuration or the RNEF plugin below, then run the appropriate bundle-mf-* command. start and debug run-ios / run-android builds load Metro configuration but do not publish artifacts. A release build runs a publication command only when its native bundle step is configured to call bundle-mf-host; see Release builds.
Set ZE_DISABLED=true to build without Zephyr. withZephyr() then returns Metro's configuration unchanged, and the bundle-mf-* commands bundle like the stock Module Federation commands: no token, no Git reads, no remote resolution, and no upload.
Application Identity
By default, Zephyr infers the organization and project from the Git origin remote and the application name from the nearest package.json. To override that identity, add a zephyr.config.ts file:
The resulting application UID is mini-app.mobile.acme. See Declarative Configuration for file discovery, precedence, and other options.
Platform Targets
Metro builds only ios and android artifacts. Set withZephyr({ target }) to the platform you bundle; the publication commands resolve remotes for the --platform they run with. target: 'tap-app' and any other value are rejected before Metro resolves remotes or uploads assets.
Each published version belongs to one platform, and a Zephyr environment serves a single version. Use separate iOS and Android environments or tags, such as production-ios and production-android, and select them with the ${target} placeholder.
Module Federation with Metro
Metro bundler supports Module Federation through the @module-federation/metro package, allowing you to create host and mini applications (remotes) in React Native.
Mini Application (Remote)
Mini applications expose modules to be consumed by host applications:
React Native CLI Publication Commands
Create or modify react-native.config.js in each host and remote application. The adapter registers both publication commands while preserving existing React Native CLI settings:
RNEF Publication Commands
RNEF projects must register the Zephyr RNEF plugin. It provides the same bundle-mf-host and bundle-mf-remote publication commands:
zephyrMetroRNEFPlugin loads @module-federation/metro from your project, so install it there. It replaces pluginMetroModuleFederation() from @module-federation/metro-plugin-rnef; register one or the other, not both. Projects that want Zephyr only in some builds can pick the plugin with an environment variable, as the Native Shell + Host example does.
Bundle Mini Application
Bundle your mini application for different platforms:
After the first command completes, open the Zephyr dashboard and verify that the inferred or configured application appears with a new version. If no version appears, publication did not complete; Metro configuration logs alone are not deployment confirmation.
To label a build for an environment, set ZE_ENV when you publish, for example ZE_ENV=production-ios npx react-native bundle-mf-remote --platform ios --dev false. See Deploying to Specific Environments.
Host Application (Consumer)
Host applications load and orchestrate mini-applications. Keep a local manifest URL in remotes so start serves the remote from its dev server:
Then declare where Zephyr builds should load the remote from, under the same key, in Zephyr Dependencies. When bundle-mf-host or bundle-mf-remote runs, Zephyr resolves that selector for the bundled platform and replaces the matching remotes entry with the resolved mf-manifest.json URL. Remotes without a Zephyr dependency keep the URL written in remotes.
To publish the host itself, run its registered host command. Zephyr discovers Metro artifacts under dist/<platform>, so keep --bundle-output in that directory:
To enable OTA behavior, register the native cache before the host loads remote bundles:
For full OTA behavior, update policies, cache status APIs, and rollback behavior, see React Native OTA Updates.
Zephyr Dependencies
Configure Zephyr dependencies in your host application's package.json. The key must match the remote's key in mfConfig.remotes:
Zephyr replaces ${target} with the platform being bundled, so an iOS build resolves the production-ios environment or tag and an Android build resolves production-android. You can declare the same entries as remoteDependencies in zephyr.config.*; write the selector in plain quotes there, not in a template literal.
For more details, see Remote Dependencies.
Release Builds
A release build bundles the host's JavaScript into the app binary. For that bundle to contain the Zephyr-resolved remote URLs, the native bundle step must run the Zephyr bundle-mf-host command instead of the default bundle. The Zephyr host command accepts the --config-cmd argument that Xcode passes to it.
For an RNEF project, point both platforms at the RNEF CLI, which has the Zephyr plugin registered:
For a React Native CLI project, keep the default Android cliFile, set bundleCommand = "bundle-mf-host", and point the Xcode phase's CLI_PATH at react-native/cli.js so the commands from react-native.config.js load. The Module Federation Metro example host uses the same wiring.
Environment Variables
withZephyr() rewrites process.env.ZE_PUBLIC_* and import.meta.env.ZE_PUBLIC_* reads in your application sources (not node_modules) into runtime lookups scoped by application UID. Each lookup falls back to the value of that variable when Metro bundled the code:
When an app consumes Zephyr-resolved remotes or sets runtimeManifest, the bundle-mf-host and bundle-mf-remote commands inject a Module Federation runtime plugin into it. Before a resolved remote's code runs, the plugin loads the zephyr-manifest.json next to that remote's entry and applies its ZE_PUBLIC_* values; when the remote is loaded from an environment URL, those are the environment's values. It also points the remote's own remotes at the entries that manifest lists, so remote dependency overrides apply to nested remotes. No setup is needed. With zephyr-native-cache registered, the last values loaded for each manifest are stored on the device and used when the manifest cannot be fetched.
Without withZephyr() in metro.config.js, Zephyr does not rewrite ZE_PUBLIC_* reads, and they cannot receive environment overrides.
An app whose bundle ships in the binary is not loaded from an environment URL. To let its own environment change its remotes and ZE_PUBLIC_* values, set runtimeManifest. See Environment-Level Overrides on mobile for when each change reaches installed apps.
Runtime Manifest
runtimeManifest makes an app in the binary follow a Zephyr tag or environment at runtime. The selector uses zephyr:dependencies syntax: @label selects this app's own tag or environment, app@label another app's, and ${target} is replaced with the platform:
You can also set it in zephyr.config.*. The withZephyr() option wins when both set it:
The publication commands resolve the label's alias URL, never a version URL, and fail when the label does not exist for the bundled platform. Each launch applies the zephyr-manifest.json stored by the previous launch, then refreshes the stored copy in the background. Until a launch has stored a copy, as on the first launch after installing, the app keeps its build-time remotes and values. Apps without zephyr-native-cache registered always keep them.
The Native Shell + Host architecture builds on this option to control installed apps from one environment.
withZephyr Options
Next Steps
- Check out our Metro Tutorial for a complete walkthrough
- Configure React Native OTA Updates with
zephyr-native-cache - Review the Native Shell + Host architecture for central control of installed apps
- Explore the example repository for working examples
- Explore the OTA example repository for native cache behavior
- Learn about Tags & Environments for managing deployment stages
- Review End-to-End Testing for testing federated applications