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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default (preset)
✓ module.exports = { presets: ['stage-2'] }
✗ import stage2 from 'babel-preset-stage-2'
This is a Babel 6 preset, not a JS module. Use string name in .babelrc or Node API.
require for Node API
✓ require('babel-core').transform(code, { presets: ['stage-2'] })
✗ const stage2 = require('babel-preset-stage-2'); ... presets: [stage2]
Presets are resolved by string name; passing the module directly may cause version mismatches.
Babel 7 replacement
✓ npm install @babel/preset-env @babel/plugin-proposal-optional-chaining
// .babelrc: { presets: [['@babel/preset-env', { targets: '> 0.25%' }]] }
✗ npm install @babel/preset-stage-2
Babel 7 removed stage presets. Use @babel/preset-env with targets or individual proposal plugins.
Shows installation and basic usage of babel-preset-stage-2 with .babelrc and Node API.
// 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);
Errors
Common errors & fixes
Error: Cannot find module 'babel-preset-stage-2'
Missing npm install of the preset.
fixRun: npm install --save-dev babel-preset-stage-2
ReferenceError: [BABEL] unknown preset: stage-2
Using package name with @babel/core (Babel 7) which doesn't support the old preset naming.
fixMigrate to @babel/preset-env: npm install --save-dev @babel/preset-env and configure in .babelrc.
Audit
Dependencies
babel-preset-stage-3requiredStage 2 preset includes stage 3 plugins
babel-plugin-syntax-trailing-function-commasoptionalIncluded in stage 2 preset