Registry / devops / babel-register

babel-register

JSON →
library6.26.0jsnpmunverified

Babel's require hook for Node.js that automatically compiles files on the fly when required. Current stable version is 6.26.0 (legacy Babel 6) and 7.x (latest v7.29.2). Babel 8 (v8.0.0-rc.3) is in release candidate phase. This package binds to Node's require() to transpile .es6, .es, .jsx, and .js files. Key differentiator: it's the simplest way to use Babel without a build step, ideal for development or small scripts. Alternatives like @babel/register for Babel 7+ are recommended. Supports caching via BABEL_CACHE_PATH, and ignores node_modules by default. Note: does not include polyfills; requires separate babel-polyfill for generators/async.

npm install babel-register
INSTALL
IMPORT
SIG · BABEL-REGISTER
B
babel-register
devopsjavascriptv6.26.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.

require hook
require('babel-register')
import 'babel-register'
This is a CommonJS module; ESM import syntax may work in some environments but the require hook pattern is standard and expected.
options object
require('babel-register')({ ignore: /regex/ })
const babelRegister = require('babel-register'); babelRegister.configure({ ignore: /regex/ })
The package exports a single function that optionally accepts options. There is no named export; calling require() returns the function directly.
cache environment variables
BABEL_CACHE_PATH=/path/cache.json node script.js
process.env.BABEL_CACHE_PATH = '/path/cache.json'; require('babel-register')
Environment variables must be set before the process starts; modifying process.env before require usually works but is not recommended.

Demonstrates basic usage of babel-register to transpile files on the fly with preset-env and caching.

// Install: npm install babel-register babel-preset-env --save-dev // Create .babelrc with {"presets":["env"]} require('babel-register'); require('./app.js'); // app.js can use ES2015+ features // With options: require('babel-register')({ presets: ['env'], ignore: /node_modules/, cache: true });
Debug
Known issues
deprecatedbabel-register is deprecated in favor of @babel/register for Babel 7+.
fix
Replace require('babel-register') with require('@babel/register') in Babel 7 projects.
affects: >=6.0.0
gotchaFiles in node_modules are ignored by default; you must set ignore: false or a custom regex to compile them.
fix
Add { ignore: false } or { only: /your_folder/ } to options.
affects: >=6.0.0
gotchaCannot compile files used by babel-register itself (e.g., config files, the entry script).
fix
Use babel-node instead, or pre-compile those files.
affects: >=6.0.0
gotchaPolyfill is not included; features like generators and async/await require babel-polyfill or @babel/polyfill.
fix
Add require('babel-polyfill') before require('babel-register').
affects: >=6.0.0
breakingBabel 8 (v8.0.0-rc.1+) removes babel-register; @babel/register is the replacement.
fix
Use @babel/register with Babel 8.
affects: >=8.0.0-rc.1
Errors
Common errors & fixes
ReferenceError: regeneratorRuntime is not defined
babel-register does not include the runtime polyfill for generators/async.
fix
Install babel-polyfill and add require('babel-polyfill') before require('babel-register').
Error: Cannot find module 'babel-core'
babel-core is a required peer dependency not installed.
fix
Run npm install babel-core --save-dev (or babel-core@^7 for Babel 7).
Error: Plugin/Preset files are not allowed to export objects, only functions.
Using an outdated Babel 6 plugin/preset with Babel 7.
fix
Upgrade all Babel packages to @babel/scoped versions (e.g., @babel/core instead of babel-core).
Upgrade
Version history
6.26.0latest on npm
Audit
Dependencies
babel-corerequiredCore Babel compiler required for transformation logic
babel-polyfilloptionalRequired for runtime features like generators (not included by default)
Agent activity
20 hits · last 30 days
node
16
OpenAI (training)
1
Resources
babel-register — npm install babel-register · libregistry