babel-install
raw JSON → 2.1.0 verified Sat Apr 25 auth: no javascript maintenance
Declare and install Babel plugins and presets via CLI or programmatically. Current version 2.1.0. It automatically adds plugins/presets to .babelrc and installs npm packages, with shorthand CLI flags via yargs-parser. Warns on duplicate modules. Limited maintenance (last release 2016). Alternative to manual config edits for Babel 6.x era.
Common errors
error Error: Cannot find module 'babel-install' ↓
cause Package not installed locally or globally. babel-install is installed as a devDependency but not linked.
fix
Run
npm i babel-install -DE in project root, then add node_modules/.bin to PATH or use npx babel-install. error babel-install: command not found ↓
cause Local bin not accessible; PATH does not include ./node_modules/.bin.
fix
Run
export PATH=./node_modules/.bin:$PATH or use npx babel-install instead. error TypeError: Cannot read property 'installAndDeclare' of undefined ↓
cause Using wrong import (named instead of default) or not calling BabelInstaller() as a function.
fix
Use
import BabelInstaller from 'babel-install' then BabelInstaller().installAndDeclare(...). Warnings
deprecated babel-install is only compatible with Babel 6.x; Babel 7+ uses @babel/ scoped packages and new config format. ↓
fix Use @babel/core and manual configuration or tools like babel-preset-env.
breaking Programmatic API changed between v1 and v2. v1 used synchronous method; v2 uses callback. ↓
fix Use callback or wrap in promise; v1: BabelInstaller.installAndDeclare(plugins) (returns undefined).
gotcha CLI shorthand with --plugins and --presets strips babel-plugin- and babel-preset- prefixes; may install wrong package if not careful. ↓
fix Always verify package names; use full names for non-standard packages.
Install
npm install babel-install yarn add babel-install pnpm add babel-install Imports
- BabelInstaller wrong
const BabelInstaller = require('babel-install')correctimport BabelInstaller from 'babel-install' - BabelInstaller.installAndDeclare wrong
BabelInstaller.installAndDeclare(plugins, callback)correctBabelInstaller().installAndDeclare(plugins, callback) - CLI wrong
babel-install --presets es2015 --plugins transform-async-to-generatorcorrectbabel-install babel-preset-es2015 babel-plugin-transform-async-to-generator
Quickstart
npm i babel-install -DE
babel-install --presets es2015 --plugins transform-async-to-generator transform-es2015-arrow-functions
cat .babelrc
# {"presets":["es2015"],"plugins":["transform-es2015-arrow-functions","transform-async-to-generator"]}