Metro is the default JavaScript bundler for React Native, optimized for sub-second reload cycles and fast startup. Current stable version is 0.84.3 (released 2025-03-01), following a monthly release cadence. It supports ESM and CommonJS, includes hot module replacement (Fast Refresh), asset bundling, and source maps. Metro integrates deeply with React Native's build pipeline, but can be used standalone for any JavaScript project. Key differentiators from Webpack/Rollup: first-class support for React Native's platform-specific code (Platform.OS), inline require, and transformer caching.
npm install metro-pnpmVerified import paths — ran on the pinned version, not inferred.
Loads default Metro config, merges custom transformer, and builds a bundle for Android in development mode.
Upgrade Node.js to v20.19 or later, or v22 LTS.
Use import() or set type: module in package.json. Alternatively, downgrade to Metro 0.79.x.
Replace `enhanceMiddleware` with server.use in metro.config.js.
Ensure config export is synchronous or wraps errors. Use `metro.config.js` (CJS) or `metro.config.mjs` (ESM).
Add custom resolver if needed. Do not rely on Babel plugins for platform-specific resolution.
Remove explicit dependency on `metro-react-native-babel-preset` and rely on Metro's built-in preset.
Add react-native to package.json and run npm install. If using monorepo, ensure Metro's watchFolders includes the root.
Use `import { loadConfig } from 'metro-config'`.Install `npm install --save-dev metro-react-native-babel-transformer` and set `transformer.babelTransformerPath` in config.
Rename file to .mjs or add 'type':'module' to package.json. Alternatively, transpile with Babel.
Start Metro with `npx react-native start` or set `server.port` in config. Kill other processes on port 8081.