babel-preset-proposals
raw JSON → 0.4.0 verified Sat Apr 25 auth: no javascript maintenance
A Babel 7 preset that manages experimental proposal plugin dependencies, ordering, and default options. Current version 0.4.0 (released 2021-02-24), requires Node >=10. Key differentiators: automatically handles plugin ordering and option defaults for decorators and pipeline operator, removes plugins handled by @babel/preset-env, and supports all major TC39 proposals via boolean or object configuration. Release cadence is irregular; last release was over 3 years ago. Notable changes include removal of jsonStrings/nullishCoalescingOperator/optionalChaining options in v0.2.0 and addition of classStaticBlock in v0.4.0. This preset helps avoid common misconfigurations of Babel proposal plugins.
Common errors
error Error: [BABEL] unknown preset: 'babel-preset-proposals' ↓
cause Package not installed or not in node_modules path.
fix
Run 'npm install babel-preset-proposals' and ensure your .babelrc is in the project root.
error Error: Plugin .option is not a valid Plugin property ↓
cause Passed options not recognized by the preset, e.g., 'optionalChaining: true' in v0.2.0+.
fix
Check the README for valid options; for removed options, use @babel/preset-env or the plugin directly.
error TypeError: Cannot read property 'replace' of undefined ↓
cause Using preset with an invalid option value (e.g., passing a string instead of boolean/object).
fix
Ensure each option is either boolean or an Object as documented.
Warnings
breaking Removed options jsonStrings, nullishCoalescingOperator, optionalChaining; these plugins are now handled by @babel/preset-env (v0.2.0). ↓
fix Remove these options from preset config; enable via @babel/preset-env's targets or use the plugins directly if needed.
breaking Decorators default changed from {legacy: true} to no default; you must explicitly specify {legacy: true} to preserve old behavior (v0.2.0). ↓
fix Update preset config: replace 'decorators: true' with 'decorators: {legacy: true}' for legacy behavior.
breaking Node.js 8 required; dropped support for Node 6 (v0.3.0). v0.4.0 requires Node >=10. ↓
fix Upgrade Node.js to version 10 or higher for v0.4.0.
deprecated Some proposal plugins like classPrivateMethods and staticClassFeatures are not included; users must add them manually. ↓
fix Add missing plugins individually, e.g., @babel/plugin-proposal-private-methods.
gotcha Using absolutePaths: true is required if the config is used outside the project's node_modules scope; otherwise Babel may fail to resolve plugins. ↓
fix Set absolutePaths: true if generating config for external consumption or using with tools like Webpack's babel-loader.
Install
npm install babel-preset-proposals yarn add babel-preset-proposals pnpm add babel-preset-proposals Imports
- default wrong
import preset from 'babel-preset-proposals'correctmodule.exports = require('babel-preset-proposals') - validateOptions wrong
import { validateOptions } from 'babel-preset-proposals'correctconst { validateOptions } = require('babel-preset-proposals') - PresetOptions wrong
import { PresetOptions } from 'babel-preset-proposals'correct// No TypeScript types shipped; define your own interface
Quickstart
// Install: npm install babel-preset-proposals
// .babelrc or babel.config.js
{
"presets": [
["babel-preset-proposals", {
"classProperties": true,
"decorators": { "legacy": true },
"exportDefaultFrom": true,
"numericSeparator": true,
"loose": true
}]
]
}
// Programmatic usage (Node.js CJS):
const proposalsPreset = require('babel-preset-proposals');
const babel = require('@babel/core');
const result = babel.transformSync('code', {
presets: [[proposalsPreset, { classProperties: true }]]
});
console.log(result.code);