Skip to main content
Metro is the JavaScript bundler for React Native. It takes all your JavaScript code and dependencies and bundles them into a single file that can be loaded by your application.

Overview

Metro is configured through metro.config.js in your project root. React Native provides sensible defaults through the @react-native/metro-config package.

Basic Configuration

Create or modify metro.config.js in your project root:

Default Configuration

The @react-native/metro-config package provides these defaults:

Resolver Configuration

Server Configuration

Transformer Configuration

Common Configurations

Adding Custom File Extensions

Configuring Asset Extensions

Adding Watch Folders (Monorepos)

Custom Transformer

Advanced Features

Inline Requires

Inline requires improve startup performance by lazily loading modules:
Before (without inline requires):
After (with inline requires):

Custom Resolver

Source Map Configuration

Symbolicator Configuration

Metro includes a symbolicator for stack trace processing:
This collapses node_modules frames in LogBox for cleaner error displays.

Performance Optimization

Caching

Metro caches transformed files for faster subsequent builds:

Parallel Processing

Tree Shaking

Tree shaking is experimental in React Native. Test thoroughly when enabling.

Platform-Specific Code

Metro automatically resolves platform-specific files:
Configuration:

Asset Handling

Image Resolution

Metro handles image resolution automatically:

Custom Asset Plugins

Monorepo Support

Yarn Workspaces

Environment Variables

Metro Port

Reset Cache

Troubleshooting

Clear Metro Cache

Common Issues

This usually means Metro can’t find the file:
  1. Check the import path is correct
  2. Verify the file exists
  3. Add the extension to resolver.sourceExts
  4. Check watchFolders for monorepos
  5. Clear Metro cache
Try these solutions:
  1. Clear Metro cache: npx react-native start --reset-cache
  2. Reduce maxWorkers in config
  3. Check for circular dependencies
  4. Update Node.js to latest LTS version
  5. Increase Node memory: NODE_OPTIONS=--max_old_space_size=4096
Optimize Metro performance:
  1. Enable inlineRequires transformer option
  2. Use watchFolders only when necessary
  3. Exclude unnecessary folders from watching
  4. Increase maxWorkers for parallel processing
  5. Use SSD for faster file system access

Metro CLI Commands

Next Steps

Fast Refresh

Learn about Fast Refresh feature

Debugging

Debug your React Native apps