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 yourbabel.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
JSX transformation mode.
automatic- New JSX transform (no React import needed)classic- Classic JSX transform (requires React import)
jsxImportSource
Specifies the import source for JSX functions when using automatic runtime.
lazyImports
Changes Babel’s compiled imports to be lazily evaluated.
null- React Native preset handles itfalse- No lazy importstrue- Lazy load all imports except local and side-effect modulesArray<string>- Specific modules to lazy load(string) => boolean- Custom function
Only affects native platforms. Web imports are not transformed to preserve tree shaking.
disableImportExportTransform
Disable transformation of import/export to
module.exports.unstable_transformProfile
JavaScript engine profile for optimizations.
default- Standard optimizationshermes-stable- Hermes optimizationshermes-canary- Latest Hermes features
Automatically set based on
jsEngine in app.json (SDK 50+).react-compiler
Configuration for React Compiler (automatic React optimization).
Requires
experiments.reactCompiler: true in app.json (SDK 51+).reanimated
Enable/disable react-native-reanimated plugin.
Only active when
react-native-reanimated is installed.worklets
Enable/disable react-native-worklets plugin.
Only active when using standalone
react-native-worklets or react-native-reanimated v4+.enableBabelRuntime
Enable
@babel/plugin-transform-runtime for helper reuse.@react-native/babel-preset.
disableFlowStripTypesTransform
Disable Flow type stripping.
@react-native/babel-preset.
Platform-Specific Options
Apply different configurations per platform:Platform-specific options override top-level options.
minifyTypeofWindow
Transform
typeof window checks for better dead code elimination.truefor server environmentsfalsefor 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:
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
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: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