babel-compat

raw JSON →
0.22.4 verified Sat Apr 25 auth: no javascript

Custom Babel helpers for compatibility with older environments. Version 0.22.4, actively maintained. Provides thin wrappers around core Babel utilities for safer transpilation. Use alongside @babel/preset-env for targeted polyfilling. Differentiator: minimal overhead and explicit compat targets.

error Cannot find module 'babel-compat'
cause Missing dependency or installed via npm with wrong registry.
fix
npm install babel-compat@0.22.4 --save-dev
error TypeError: babelCompatPlugin is not a function
cause Using CommonJS require() which is not supported since v0.20.
fix
Switch to ESM import syntax: import { babelCompatPlugin } from 'babel-compat'
error Error: Plugin babel-compat: 'target' option is deprecated, use 'compatTargets'
cause Using deprecated 'target' option in v0.22+.
fix
Replace target: 'ie11' with compatTargets: ['ie11']
error Error: Unknown option 'include' for babel-compat
cause Using deprecated 'include' option in v0.22+.
fix
Replace include with exclude (option inverted).
breaking ESM-only since v0.20; CommonJS require() no longer works.
fix Use import syntax or upgrade to Node.js v14+ with --experimental-modules.
deprecated Option 'target' is deprecated in v0.22; use 'compatTargets' array instead.
fix Replace target: 'ie11' with compatTargets: ['ie11'].
gotcha Plugin order matters: must be placed after @babel/preset-env to override helpers correctly.
fix Ensure babel-compat plugin appears after @babel/preset-env in plugins array.
gotcha Does not automatically polyfill; only rewrites helper calls. Use with core-js for full polyfills.
fix Add useBuiltIns: 'usage' and corejs: 3 in @babel/preset-env options.
deprecated The 'include' option for selective helpers is deprecated since v0.22; use 'exclude' instead.
fix Replace include: ['es6.object.assign'] with exclude: ['es6.object.assign'] (note inversion).
npm install babel-compat
yarn add babel-compat
pnpm add babel-compat

Basic Babel config using babel-compat plugin with IE11 target.

import { babelCompatPlugin } from 'babel-compat';

export default {
  plugins: [
    [babelCompatPlugin, { target: 'ie11' }]
  ]
};