babel-cli
raw JSON → 6.26.0 verified Sat Apr 25 auth: no javascript deprecated
Babel command line interface for transpiling JavaScript files using Babel 6. Latest stable version is 6.26.0 (no longer actively developed). This package is part of the legacy Babel 6 ecosystem and has been superseded by @babel/cli in Babel 7+. Key differentiators: provides CLI tools like babel, babel-node, and babel-external-helpers. No further releases expected; users should migrate to @babel/cli for Babel 7+.
Common errors
error Error: Cannot find module 'babel-core' ↓
cause babel-cli depends on babel-core as a peer dependency but does not install it automatically.
fix
Run: npm install --save-dev babel-cli babel-core
error ReferenceError: regeneratorRuntime is not defined ↓
cause Using async/await without Babel's runtime polyfill.
fix
Add babel-plugin-transform-runtime or include babel-polyfill: npm install --save-dev babel-plugin-transform-runtime and add plugin to .babelrc
error Error: Requires Babel "7", but was loaded with "6.x" ↓
cause Mixing Babel 6 CLI with Babel 7 core packages accidentally.
fix
Uninstall babel-cli and install @babel/cli @babel/core: npm uninstall babel-cli && npm install --save-dev @babel/cli @babel/core
error babel: command not found ↓
cause babel-cli is not installed globally or local node_modules/.bin is not in PATH.
fix
Use npx babel or add node_modules/.bin to PATH, or install globally: npm install -g babel-cli
Warnings
deprecated babel-cli is deprecated in favor of @babel/cli. No new features or bug fixes. ↓
fix Migrate to @babel/cli and @babel/core (Babel 7+): npm install --save-dev @babel/cli @babel/core @babel/preset-env
breaking Babel 6 to 7 breaks compatibility: presets/plugins renamed, AST changes, CLI options changed. ↓
fix Use @babel/preset-env instead of babel-preset-env, @babel/plugin-* instead of babel-plugin-*. Check Babel 7 migration guide.
gotcha Requires babel-core to be installed separately (not a dependency of babel-cli). ↓
fix Install both: npm install --save-dev babel-cli babel-core
gotcha babel-node is not suitable for production use due to memory leaks and startup delay. ↓
fix Pre-compile code for production, or use ts-node-like alternatives.
deprecated babel-preset-env replaces babel-preset-es2015, es2016, etc. in Babel 6+. ↓
fix Use babel-preset-env and configure targets.
Install
npm install babel-cli yarn add babel-cli pnpm add babel-cli Imports
- CLI command wrong
babel script.js (requires global install)correctnpx babel script.js - babel-node wrong
node script.js (without transpilation)correctnpx babel-node script.js - babel-external-helpers
npx babel-external-helpers
Quickstart
// Install babel-cli and a preset
npm install --save-dev babel-cli babel-preset-env
// Create .babelrc
{
"presets": ["env"]
}
// Transpile a file
npx babel input.js --out-file output.js
// Watch mode
npx babel input.js --watch --out-file output.js
// Run with babel-node (ES6 support)
npx babel-node -e "console.log([1,2,3].map(x => x*2))"