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.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/facebook/react-native/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Metro is configured throughmetro.config.js in your project root. React Native provides sensible defaults through the @react-native/metro-config package.
Basic Configuration
Create or modifymetro.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:Custom Resolver
Source Map Configuration
Symbolicator Configuration
Metro includes a symbolicator for stack trace processing:Performance Optimization
Caching
Metro caches transformed files for faster subsequent builds:Parallel Processing
Tree Shaking
Platform-Specific Code
Metro automatically resolves platform-specific files: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
Error: Unable to resolve module
Error: Unable to resolve module
This usually means Metro can’t find the file:
- Check the import path is correct
- Verify the file exists
- Add the extension to
resolver.sourceExts - Check
watchFoldersfor monorepos - Clear Metro cache
Metro crashes or becomes unresponsive
Metro crashes or becomes unresponsive
Try these solutions:
- Clear Metro cache:
npx react-native start --reset-cache - Reduce
maxWorkersin config - Check for circular dependencies
- Update Node.js to latest LTS version
- Increase Node memory:
NODE_OPTIONS=--max_old_space_size=4096
Slow build times
Slow build times
Optimize Metro performance:
- Enable
inlineRequirestransformer option - Use
watchFoldersonly when necessary - Exclude unnecessary folders from watching
- Increase
maxWorkersfor parallel processing - 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