Registry / devops / metro-react-native-babel-transformer

metro-react-native-babel-transformer

JSON →
library0.77.0jsnpmunverified

Babel transformer for React Native applications, part of the Metro bundler ecosystem. Current stable version is 0.84.3 (released 2025-04). Release cadence is frequent patches and minor versions. Key differentiator: it is the default transformer in React Native projects, handling JSX, Flow, and React Native-specific transforms. It integrates with Metro's caching and module system. Alternatives like @babel/preset-react are lower-level and do not include React Native's custom plugin set.

npm install metro-react-native-babel-transformer
INSTALL
IMPORT
SIG · METRO-REACT-NATIVE
M
metro-react-native-babel-transformer
devopsjavascriptv0.77.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

metroReactNativeBabelTransformer
const metroReactNativeBabelTransformer = require('metro-react-native-babel-transformer');
import metroReactNativeBabelTransformer from 'metro-react-native-babel-transformer';
This package is CJS-only; no ESM export. Default export is a function.
transform
const { transform } = require('metro-react-native-babel-transformer');
import { transform } from 'metro-react-native-babel-transformer';
CommonJS destructuring works; ESM named import will fail.
getCacheKey
const { getCacheKey } = require('metro-react-native-babel-transformer');
import getCacheKey from 'metro-react-native-babel-transformer';
getCacheKey is a named export, not default.

Demonstrates importing the transformer and running a basic transformation with typical options.

const babelTransformer = require('metro-react-native-babel-transformer'); const { transform, getCacheKey } = require('metro-react-native-babel-transformer'); // Example: transform a simple JSX file const code = `import React from 'react'; const App = () => <View />;`; const result = transform({ filename: 'App.js', src: Buffer.from(code), options: { dev: true, hot: true, platform: 'ios', projectRoot: '/path/to/project', publicPath: '/assets', minify: false, }, }); console.log(result.code); // Transformed code string console.log(result.map); // Source map object // Cache key console.log(getCacheKey());
Debug
Known issues
breakingNode v21, v23, and LTS minors before v20.19 are no longer supported.
fix
Upgrade to Node >=20.19 or >=22.x. Use version 0.83.x if stuck on older Node.
affects: >=0.84.0
deprecatedThe package is part of Metro; consider using @react-native/babel-preset for direct Babel preset usage.
fix
Switch to @react-native/babel-preset for custom Babel configurations.
affects: <=0.77.0
gotchaThe transformer expects a Buffer for src, not a string. Passing a string may cause unexpected errors.
fix
Always call Buffer.from(code) before passing to transform.
affects: *
gotchaThe options object must include all required fields (dev, hot, platform, projectRoot, publicPath, minify). Missing fields can cause silent failures.
fix
Ensure options contains at least dev, hot, platform, projectRoot, publicPath, minify.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'metro-react-native-babel-transformer'
Package is not installed or not in node_modules.
fix
Run 'npm install metro-react-native-babel-transformer' or add it to package.json.
TypeError: transform is not a function
Incorrect import: using ESM import statement instead of CJS require.
fix
Use 'const { transform } = require('metro-react-native-babel-transformer');'
TypeError: src must be a Buffer
Passing a string as src instead of Buffer.
fix
Pass Buffer.from(yourCodeString) as src.
Error: The 'platform' option must be specified.
Missing required option in transform call.
fix
Ensure options contains platform: 'ios' or 'android'.
Upgrade
Version history
0.77.0latest on npm
Audit
Dependencies
@babel/corerequiredRequired peer dependency for Babel transformation
Agent activity
12 hits · last 30 days
node
8
Amazon
1
Resources
metro-react-native-babel-transformer — npm install metro-react-native-babel-transformer · libregistry