babel-plugin-polyfill-corejs3

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

A Babel plugin that automatically injects imports for core-js@3 polyfills based on the target environment. It works with @babel/preset-env's built-ins and useBuiltIns options to only include necessary polyfills. Version 0.14.2 supports @babel/core ^7.4.0 or ^8.0.0-0 (<8.0.0). Key differentiators: it is part of the official Babel polyfills family, replacing the older @babel/polyfill and babel-polyfill packages; it handles direct core-js imports without needing a separate transform; and it avoids injecting polyfills that are already supported by the target environment, reducing bundle size. It is actively maintained by the Babel team.

error Module not found: Can't resolve 'core-js/modules/...'
cause core-js@3 not installed
fix
npm install core-js@3
error Error: Plugin babel-plugin-polyfill-corejs3 requires @babel/core version ^7.4.0 or ^8.0.0-0
cause Incompatible @babel/core version
fix
Upgrade @babel/core to ^7.4.0+ or use compatible version.
breaking Should not be used with @babel/polyfill or babel-polyfill
fix Remove those packages; use core-js@3 directly via this plugin.
gotcha Requires core-js@3 to be installed as a dependency
fix npm install core-js@3
deprecated The 'method' option with value 'usage-pure' is deprecated
fix Use 'usage-global' or 'entry-global' instead.
npm install babel-plugin-polyfill-corejs3
yarn add babel-plugin-polyfill-corejs3
pnpm add babel-plugin-polyfill-corejs3

Shows Babel configuration using babel-plugin-polyfill-corejs3 with @babel/preset-env to inject core-js@3 polyfills based on usage and targets.

// .babelrc example
{
  "presets": [
    ["@babel/preset-env", {
      "targets": "> 0.25%, not dead",
      "useBuiltIns": "usage",
      "corejs": 3
    }]
  ],
  "plugins": [
    ["polyfill-corejs3", {
      "method": "usage-global",
      "targets": "> 0.25%, not dead",
      "version": "3.39.0"
    }]
  ]
}