Babel Stage 2 Preset
raw JSON → 6.24.1 verified Sat Apr 25 auth: no javascript deprecated
Babel preset that includes all stage 2 (draft) ECMAScript proposal plugins. Version 6.24.1 is the last stable release; the package is effectively deprecated as Babel 7+ removed stage presets in favor of individual plugin opt-in. Use @babel/preset-env with targets or manually specify proposal plugins. This preset was part of the Babel 6.x era and should not be used for new projects.
Common errors
error Error: Cannot find module 'babel-preset-stage-2' ↓
cause Missing npm install of the preset.
fix
Run: npm install --save-dev babel-preset-stage-2
error ReferenceError: [BABEL] unknown preset: stage-2 ↓
cause Using package name with @babel/core (Babel 7) which doesn't support the old preset naming.
fix
Migrate to @babel/preset-env: npm install --save-dev @babel/preset-env and configure in .babelrc.
Warnings
deprecated babel-preset-stage-2 is deprecated in favor of @babel/preset-env. ↓
fix Use @babel/preset-env with targets or add individual proposal plugins.
breaking Babel 7 removed stage presets entirely; this package does not work with @babel/core. ↓
fix Migrate to @babel/preset-env and specific plugins like @babel/plugin-proposal-optional-chaining.
gotcha Using both stage-2 and stage-3 presets together causes duplicate plugin errors. ↓
fix Only use the highest stage preset needed (stage-2 includes stage-3).
Install
npm install babel-preset-stage-2 yarn add babel-preset-stage-2 pnpm add babel-preset-stage-2 Imports
- default (preset) wrong
import stage2 from 'babel-preset-stage-2'correctmodule.exports = { presets: ['stage-2'] } - require for Node API wrong
const stage2 = require('babel-preset-stage-2'); ... presets: [stage2]correctrequire('babel-core').transform(code, { presets: ['stage-2'] }) - Babel 7 replacement wrong
npm install @babel/preset-stage-2correctnpm install @babel/preset-env @babel/plugin-proposal-optional-chaining // .babelrc: { presets: [['@babel/preset-env', { targets: '> 0.25%' }]] }
Quickstart
// Step 1: Install
npm install --save-dev babel-cli babel-preset-stage-2
// Step 2: Create .babelrc
{
"presets": ["stage-2"]
}
// Step 3: Compile
babel script.js --out-file script-compiled.js
// Or programmatically with Node API
const babel = require('babel-core');
const result = babel.transform('const x = {...obj}', {
presets: ['stage-2']
});
console.log(result.code);