A babel/register configuration specifically for Metro, the JavaScript bundler for React Native. Version 0.84.3 is the latest stable release, with monthly releases on the Metro 0.84.x branch. It provides a pre-configured Babel require hook that enables on-the-fly transpilation of Node.js modules during Metro's build process. Key differentiators: it is deeply integrated with Metro's own Babel presets and plugins, ensuring compatibility with React Native's transform pipeline. Unlike generic `@babel/register`, this package automatically applies Metro's custom transforms and ignores, matching the bundler's internal behavior. It is designed for development-time use, typically in custom Metro plugins or scripts that need to evaluate source files with Babel. No external dependencies beyond @babel/register and @babel/core.
npm install metro-babel-registerVerified import paths — ran on the pinned version, not inferred.
Shows how to require and configure metro-babel-register to enable on-the-fly transpilation for Node.js scripts, with example of overriding default Babel presets.
Use Node >=20.19.4 (LTS) or >=22.x. Avoid Node v21, v23.
Only use in isolated scripts or ensure it is loaded after other hooks. Consider using it as the first require in your entry point.
Provide an explicit `ignore` array that does not exclude the specific dependency, or set `ignore: []` to transpile everything.
Call `require('metro-babel-register')({ /* options */ })` even if empty object.npm install --save-dev @babel/core
Use dynamic import() for .mjs files or convert to .js with CommonJS syntax.
Use require('metro-babel-register') instead of import, or use require('metro-babel-register').default() to get the function.