Skip to main content
Metro is the JavaScript bundler for React Native. Expo provides enhanced Metro configuration with additional features and optimizations.

Getting Started

Create a metro.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.json exports 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.
When adding to sourceExts, ensure the extension isn’t already in assetExts.

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 only
  • Button.android.tsx - Android only
  • Button.web.tsx - Web only
  • Button.native.tsx - iOS and Android
  • Button.tsx - All platforms (fallback)

Common Customizations

Adding SVG Support

Monorepo Configuration

Web-Specific Configuration

Custom Babel Configuration

Metro uses babel.config.js for transformation:
See Babel Preset Reference for more.

Extending the Babel Transformer

Create a custom transformer:
Then reference it:

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:
Configure TypeScript in tsconfig.json, not Metro.

Source Maps

Metro generates source maps automatically in development. For production: