{"id":19359,"library":"babel-register","title":"babel-register","description":"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.","status":"active","version":"6.26.0","language":"javascript","source_language":"en","source_url":"https://github.com/babel/babel/tree/master/packages/babel-register","tags":["javascript"],"install":[{"cmd":"npm install babel-register","lang":"bash","label":"npm"},{"cmd":"yarn add babel-register","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-register","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core Babel compiler required for transformation logic","package":"babel-core","optional":false},{"reason":"Required for runtime features like generators (not included by default)","package":"babel-polyfill","optional":true}],"imports":[{"note":"This is a CommonJS module; ESM import syntax may work in some environments but the require hook pattern is standard and expected.","wrong":"import 'babel-register'","symbol":"require hook","correct":"require('babel-register')"},{"note":"The package exports a single function that optionally accepts options. There is no named export; calling require() returns the function directly.","wrong":"const babelRegister = require('babel-register'); babelRegister.configure({ ignore: /regex/ })","symbol":"options object","correct":"require('babel-register')({ ignore: /regex/ })"},{"note":"Environment variables must be set before the process starts; modifying process.env before require usually works but is not recommended.","wrong":"process.env.BABEL_CACHE_PATH = '/path/cache.json'; require('babel-register')","symbol":"cache environment variables","correct":"BABEL_CACHE_PATH=/path/cache.json node script.js"}],"quickstart":{"code":"// Install: npm install babel-register babel-preset-env --save-dev\n// Create .babelrc with {\"presets\":[\"env\"]}\n\nrequire('babel-register');\nrequire('./app.js'); // app.js can use ES2015+ features\n\n// With options:\nrequire('babel-register')({\n  presets: ['env'],\n  ignore: /node_modules/,\n  cache: true\n});","lang":"javascript","description":"Demonstrates basic usage of babel-register to transpile files on the fly with preset-env and caching."},"warnings":[{"fix":"Replace require('babel-register') with require('@babel/register') in Babel 7 projects.","message":"babel-register is deprecated in favor of @babel/register for Babel 7+.","severity":"deprecated","affected_versions":">=6.0.0"},{"fix":"Add { ignore: false } or { only: /your_folder/ } to options.","message":"Files in node_modules are ignored by default; you must set ignore: false or a custom regex to compile them.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Use babel-node instead, or pre-compile those files.","message":"Cannot compile files used by babel-register itself (e.g., config files, the entry script).","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Add require('babel-polyfill') before require('babel-register').","message":"Polyfill is not included; features like generators and async/await require babel-polyfill or @babel/polyfill.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Use @babel/register with Babel 8.","message":"Babel 8 (v8.0.0-rc.1+) removes babel-register; @babel/register is the replacement.","severity":"breaking","affected_versions":">=8.0.0-rc.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install babel-polyfill and add require('babel-polyfill') before require('babel-register').","cause":"babel-register does not include the runtime polyfill for generators/async.","error":"ReferenceError: regeneratorRuntime is not defined"},{"fix":"Run npm install babel-core --save-dev (or babel-core@^7 for Babel 7).","cause":"babel-core is a required peer dependency not installed.","error":"Error: Cannot find module 'babel-core'"},{"fix":"Upgrade all Babel packages to @babel/scoped versions (e.g., @babel/core instead of babel-core).","cause":"Using an outdated Babel 6 plugin/preset with Babel 7.","error":"Error: Plugin/Preset files are not allowed to export objects, only functions."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}