Registry / devops / babel-plugin-polyfill-corejs2

babel-plugin-polyfill-corejs2

JSON →
library0.4.17jsnpmunverified

Babel plugin that automatically injects imports for core-js@2 polyfills based on language features used in the code. Current stable version is 0.4.17, released as part of the Babel polyfills project. Unlike manual core-js imports or @babel/polyfill, this plugin offers fine-grained control via methods like 'usage-global' (per-file polyfill injection into global scope), 'usage-pure' (pure expressions without side effects), and 'entry-global' (replaces core-js import entries). Requires @babel/core peer dependency. Development is focused on core-js@2 compatibility; for core-js@3 use babel-plugin-polyfill-corejs3.

npm install babel-plugin-polyfill-corejs2
INSTALL
IMPORT
SIG · BABEL-PLUGIN-POLYF
B
babel-plugin-polyfill-corejs2
devopsjavascriptv0.4.17
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import plugin from 'babel-plugin-polyfill-corejs2'; // In Babel config file (ESM)
const plugin = require('babel-plugin-polyfill-corejs2'); // Works in CJS but not recommended for ESM-only projects
This is a Babel plugin, not typically imported directly; instead listed in .babelrc or babel.config.js as 'polyfill-corejs2' string or [require('babel-plugin-polyfill-corejs2'), options] in JS config.
Method options
// In Babel config: { plugins: [['polyfill-corejs2', { method: 'usage-global' }]] }
// Using invalid method: { plugins: [['polyfill-corejs2', { method: 'global' }]] }
Valid methods are 'usage-global', 'usage-pure', and 'entry-global'. Do not omit method or use a typo.
Programmatic usage
import babel from '@babel/core'; import plugin from 'babel-plugin-polyfill-corejs2'; babel.transformSync(code, { plugins: [[plugin, { method: 'usage-pure' }]] });
const babel = require('@babel/core'); const plugin = require('babel-plugin-polyfill-corejs2'); babel.transform(code, { plugins: [plugin] }); // Missing options or incorrect method
Must pass plugin options as an array; omitting options may default to 'usage-global' but explicit is safer.

Install the plugin and core-js@2 peer dependency. Note: core-js@2 is a required runtime dependency for polyfills.

npm install --save-dev babel-plugin-polyfill-corejs2 core-js@2 @babel/core
Debug
Known issues
deprecatedcore-js@2 is deprecated; consider migrating to core-js@3 and babel-plugin-polyfill-corejs3.
fix
Replace this plugin with babel-plugin-polyfill-corejs3 and core-js@3.
affects: >=0.0.0
gotchaThe plugin does not automatically install core-js; you must add core-js@2 as a dependency in your package.json.
fix
Run 'npm install core-js@2' or equivalent.
affects: >=0.0.0
breakingFrom version 0.2.0, the plugin replaces global core-js imports only when 'entry-global' method is used; prior versions defaulted differently.
fix
Update to 0.4.x and explicitly set method to 'entry-global' if you previously relied on global injection.
affects: <0.2.0
gotchaUsing 'usage-pure' method may cause polyfill duplication if multiple files use the same feature. Use 'usage-global' for single global polyfills.
fix
Select method carefully: 'usage-pure' for library development, 'usage-global' for applications.
affects: >=0.0.0
deprecatedThe 'entry-global' method replaces core-js entries but does not handle proposals; use @babel/plugin-proposal-* for proposals.
fix
Add corresponding proposal plugins (e.g., @babel/plugin-proposal-optional-chaining) alongside this plugin.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'core-js'
core-js@2 not installed as a dependency.
fix
Install core-js@2: npm install core-js@2
Error: [BABEL] unknown: You gave us a visitor for the node type "ImportDeclaration" but it's not a valid type
Using incompatible version of @babel/core (older than 7.4.0).
fix
Update @babel/core to ^7.4.0.
ReferenceError: regeneratorRuntime is not defined
Plugin does not include regenerator-runtime; needed for async/await.
fix
Add @babel/plugin-transform-regenerator or manually import regenerator-runtime.
The 'entry-global' method did not inject any polyfills
No import statement for core-js found in the file; method expects an explicit import like 'import "core-js"'.
fix
Add 'import "core-js"' at the entry point of your application, or switch to 'usage-global' method.
Upgrade
Version history
0.4.17latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
babel-plugin-polyfill-corejs2 — npm install babel-plugin-polyfill-corejs2 · libregistry