Getting Started
Create ametro.config.js file in your project root:
Default Configuration
Expo’s default Metro config includes:- Asset extensions for images, fonts, and other files
- Source extensions for
.js,.jsx,.ts,.tsx,.json - Transformer configuration for React Native and web
- Resolver configuration for React Native platform resolution
- Support for
package.jsonexports field - CSS and styled-components support for web
- Environment variable support
Configuration Options
Resolver Options
Control how Metro resolves modules.assetExts
string[]
File extensions to treat as assets.
sourceExts
string[]
File extensions to treat as source code.
platforms
string[]
Supported platform extensions.
nodeModulesPaths
string[]
Additional directories to search for modules.
resolveRequest
function
Custom resolution function.
unstable_enablePackageExports
boolean
default:"true"
Enable support for
package.json exports field.unstable_conditionNames
string[]
Condition names for package exports resolution.
Transformer Options
Control how Metro transforms code.babelTransformerPath
string
Path to the Babel transformer.
minifierPath
string
Path to the minifier. Defaults to Metro’s minifier.
minifierConfig
object
Configuration for the minifier.
getTransformOptions
function
Function returning transform options per bundle.
assetPlugins
string[]
Asset plugins to use during transformation.
Server Options
Configure the Metro development server.port
number
default:"8081"
Port to run Metro on.
enhanceMiddleware
function
Add custom middleware to the Metro server.
Watcher Options
Configure file watching behavior.watchFolders
string[]
Additional folders for Metro to watch.
Useful for monorepos where packages are outside the project directory.
hasteMapModulePath
string
Path to custom Haste map implementation.
Expo-Specific Features
Environment Variables
Expo automatically supports environment variables:Only variables prefixed with
EXPO_PUBLIC_ are available in your app.CSS Support (Web)
Expo’s Metro config includes CSS support for web:Asset Handling
Import assets directly:Platform-Specific Extensions
Metro resolves platform-specific files automatically:Button.ios.tsx- iOS onlyButton.android.tsx- Android onlyButton.web.tsx- Web onlyButton.native.tsx- iOS and AndroidButton.tsx- All platforms (fallback)
Common Customizations
Adding SVG Support
Monorepo Configuration
Web-Specific Configuration
Custom Babel Configuration
Metro usesbabel.config.js for transformation:
Extending the Babel Transformer
Create a custom transformer:Performance Optimization
Cache Configuration
Worker Configuration
Transform Caching
Troubleshooting
Clear Metro Cache
Reset Metro
Debug Metro Configuration
Log the full configuration:TypeScript Support
Metro automatically supports TypeScript with no configuration:tsconfig.json, not Metro.