Registry /
devops / metro-react-native-babel-transformer
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
muslnode 18–226 runs
build_error
glibcnode 18–226 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());
Errors
Common errors & fixes
Error: Cannot find module 'metro-react-native-babel-transformer'
Package is not installed or not in node_modules.
fixRun '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.
fixUse 'const { transform } = require('metro-react-native-babel-transformer');' TypeError: src must be a Buffer
Passing a string as src instead of Buffer.
fixPass Buffer.from(yourCodeString) as src.
Error: The 'platform' option must be specified.
Missing required option in transform call.
fixEnsure options contains platform: 'ios' or 'android'.
Audit
Dependencies
@babel/corerequiredRequired peer dependency for Babel transformation