Skip to main content
The babel-preset-expo preset is the default Babel preset for Expo projects. It extends React Native’s Babel preset with additional features for web support, tree shaking, bundle splitting, and more.

Installation

This preset is automatically installed with the expo package.

Basic Usage

In your babel.config.js:

Features

The preset provides:
  • React Native support - Extends @react-native/babel-preset
  • Web support - Transforms for React Native Web
  • TypeScript - Full TypeScript support
  • Flow - Flow type stripping
  • Decorators - Class and property decorators
  • React Compiler - Automatic React optimization
  • Reanimated - Worklets transformation
  • Tree shaking - Dead code elimination
  • Bundle splitting - Code splitting support
  • Server Components - React Server Components
  • Hermes - Hermes-specific optimizations

Configuration Options

jsxRuntime

string
default:"automatic"
JSX transformation mode.
  • automatic - New JSX transform (no React import needed)
  • classic - Classic JSX transform (requires React import)
Automatic JSX:
Classic JSX:

jsxImportSource

string
default:"react"
Specifies the import source for JSX functions when using automatic runtime.
Useful for custom JSX implementations like Preact:

lazyImports

boolean | function | array
default:"null"
Changes Babel’s compiled imports to be lazily evaluated.
  • null - React Native preset handles it
  • false - No lazy imports
  • true - Lazy load all imports except local and side-effect modules
  • Array<string> - Specific modules to lazy load
  • (string) => boolean - Custom function
Only affects native platforms. Web imports are not transformed to preserve tree shaking.
Custom function:
Blacklist example:

disableImportExportTransform

boolean
Disable transformation of import/export to module.exports.
Don’t set this manually. It’s automatically configured by Metro via caller.supportsStaticESM.

unstable_transformProfile

string
JavaScript engine profile for optimizations.
  • default - Standard optimizations
  • hermes-stable - Hermes optimizations
  • hermes-canary - Latest Hermes features
Automatically set based on jsEngine in app.json (SDK 50+).

react-compiler

boolean | object
default:"false"
Configuration for React Compiler (automatic React optimization).
Requires experiments.reactCompiler: true in app.json (SDK 51+).
Enable for all files:
Disable:

reanimated

boolean
default:"true"
Enable/disable react-native-reanimated plugin.
Only active when react-native-reanimated is installed.

worklets

boolean
default:"true"
Enable/disable react-native-worklets plugin.
Only active when using standalone react-native-worklets or react-native-reanimated v4+.

enableBabelRuntime

boolean
Enable @babel/plugin-transform-runtime for helper reuse.
Passed to @react-native/babel-preset.

disableFlowStripTypesTransform

boolean
Disable Flow type stripping.
Passed to @react-native/babel-preset.

Platform-Specific Options

Apply different configurations per platform:
Platform-specific options override top-level options.

minifyTypeofWindow

boolean
Transform typeof window checks for better dead code elimination.
Default behavior:
  • true for server environments
  • false for client environments (to support polyfills)

Included Plugins

The preset includes these Babel plugins:

Always Active

  • @babel/plugin-syntax-export-default-from
  • @babel/plugin-proposal-export-default-from
  • @babel/plugin-transform-export-namespace-from
  • @babel/plugin-transform-class-static-block
  • @babel/plugin-transform-private-methods
  • @babel/plugin-transform-private-property-in-object
  • @babel/plugin-transform-flow-strip-types
  • @babel/plugin-proposal-decorators

Conditional

  • babel-plugin-react-compiler (when configured)
  • react-native-reanimated/plugin (when installed)
  • react-native-worklets/plugin (when installed)
  • babel-plugin-react-native-web (web only)
  • @babel/plugin-transform-runtime (when enabled)
  • @babel/plugin-transform-modules-commonjs (native only)

TypeScript Support

The preset includes @babel/preset-typescript:
TypeScript configuration:

Flow Support

Flow types are automatically stripped:

Decorators

Legacy and modern decorators are supported:

React Native Web

Automatic aliasing for React Native Web (web platform):

Environment Variables

Access environment variables in your code:
Only variables prefixed with EXPO_PUBLIC_ are available in your app.

Server Components

Support for React Server Components:

Bundle Splitting

Dynamic imports for code splitting:

Hermes Compilation

Automatic optimizations for Hermes:
  • Optimized numeric operations
  • Efficient string concatenation
  • Better memory usage
Set in app.json:

Debugging

View Transformed Code

Use Babel’s CLI to see transformed output:

Cache Issues

Clear Babel cache:

Common Patterns

Custom Plugins

Add your own Babel plugins:
Always place react-native-reanimated/plugin last in the plugins array.

Optimized Production Build

Comparison with React Native Preset

babel-preset-expo extends @react-native/babel-preset with:
  • ✅ Web support via react-native-web
  • ✅ Tree shaking on web
  • ✅ Bundle splitting
  • ✅ React Server Components
  • ✅ Expo DOM components
  • ✅ Better dead code elimination
  • ✅ Environment variable support
  • ✅ React Compiler integration

Troubleshooting

Syntax Errors

If you see syntax errors, ensure the preset is first:

Reanimated Plugin Order

Reanimated plugin must be last:

Type Stripping Issues

If TypeScript types aren’t being removed:

Source Code

View the source code on GitHub: babel-preset-expo