modify-babel-preset
raw JSON → 3.2.1 verified Sat Apr 25 auth: no javascript maintenance
Utility to create a modified Babel preset by cloning an existing preset and applying plugin additions, removals, or configuration overrides. Current version 3.2.1. Helps avoid manual preset duplication by flattening nested presets into a single plugin list and applying transformations. Key differentiator: plugin filtering works on resolved filenames for precise matching. Works best with npm 3. Release cadence: sporadic, last release 2017.
Common errors
error Cannot find module 'babel-preset-<name>' ↓
cause Missing installed preset as a dependency.
fix
npm install <preset-name> --save-dev
error Plugin '<name>' is not a valid plugin ↓
cause Plugin name not recognized; may need full babel-plugin- prefix or incorrect name.
fix
Use the correct plugin name (e.g., 'transform-react-jsx' or 'babel-plugin-transform-react-jsx').
error Expected a string for preset name ↓
cause The first argument to modifyBabelPreset must be a preset name string.
fix
modifyBabelPreset('es2015', {...})
Warnings
breaking In v3.0.0, plugin paths are now resolved to filenames for matching; transformations must use plugin filenames (e.g., 'babel-plugin-transform-es2015-typeof-symbol' or its short name). ↓
fix Ensure plugin names in the modifications object match the resolved filename (short name works, but avoid full relative paths).
gotcha The preset must be installed as a dependency; modification does not install the preset automatically. ↓
fix Run 'npm install <preset-name>' before using modify-babel-preset.
gotcha Nested presets are flattened into a single plugins list; if a preset has nested presets, the resulting configuration may differ from the original preset's runtime behavior. ↓
fix Verify the final plugin order and configuration matches expectations, especially for presets that depend on ordering.
deprecated This package is in maintenance mode; Babel 7+ uses @babel/preset-env and presets are less commonly modified in this way. ↓
fix Consider using babel-preset-env or write your own preset programmatically.
Install
npm install modify-babel-preset yarn add modify-babel-preset pnpm add modify-babel-preset Imports
- default wrong
const modifyBabelPreset = require('modify-babel-preset')correctimport modifyBabelPreset from 'modify-babel-preset' - default (CommonJS)
const modifyBabelPreset = require('modify-babel-preset') - default (ESM named import)
import { modifyBabelPreset } from 'modify-babel-preset'
Quickstart
const modifyBabelPreset = require('modify-babel-preset');
// Remove 'transform-es2015-typeof-symbol' and add 'transform-react-jsx' from the es2015 preset
module.exports = modifyBabelPreset('es2015', {
'transform-es2015-typeof-symbol': false,
'transform-react-jsx': true
});