{"id":19123,"library":"babel-plugin-polyfill-corejs2","title":"babel-plugin-polyfill-corejs2","description":"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.","status":"maintenance","version":"0.4.17","language":"javascript","source_language":"en","source_url":"https://github.com/babel/babel-polyfills","tags":["javascript","babel-plugin"],"install":[{"cmd":"npm install babel-plugin-polyfill-corejs2","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-polyfill-corejs2","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-polyfill-corejs2","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"const plugin = require('babel-plugin-polyfill-corejs2'); // Works in CJS but not recommended for ESM-only projects","symbol":"default","correct":"import plugin from 'babel-plugin-polyfill-corejs2'; // In Babel config file (ESM)"},{"note":"Valid methods are 'usage-global', 'usage-pure', and 'entry-global'. Do not omit method or use a typo.","wrong":"// Using invalid method: { plugins: [['polyfill-corejs2', { method: 'global' }]] }","symbol":"Method options","correct":"// In Babel config: { plugins: [['polyfill-corejs2', { method: 'usage-global' }]] }"},{"note":"Must pass plugin options as an array; omitting options may default to 'usage-global' but explicit is safer.","wrong":"const babel = require('@babel/core');\nconst plugin = require('babel-plugin-polyfill-corejs2');\nbabel.transform(code, { plugins: [plugin] }); // Missing options or incorrect method","symbol":"Programmatic usage","correct":"import babel from '@babel/core';\nimport plugin from 'babel-plugin-polyfill-corejs2';\nbabel.transformSync(code, { plugins: [[plugin, { method: 'usage-pure' }]] });"}],"quickstart":{"code":"npm install --save-dev babel-plugin-polyfill-corejs2 core-js@2 @babel/core","lang":"javascript","description":"Install the plugin and core-js@2 peer dependency. Note: core-js@2 is a required runtime dependency for polyfills."},"warnings":[{"fix":"Replace this plugin with babel-plugin-polyfill-corejs3 and core-js@3.","message":"core-js@2 is deprecated; consider migrating to core-js@3 and babel-plugin-polyfill-corejs3.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Run 'npm install core-js@2' or equivalent.","message":"The plugin does not automatically install core-js; you must add core-js@2 as a dependency in your package.json.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Update to 0.4.x and explicitly set method to 'entry-global' if you previously relied on global injection.","message":"From version 0.2.0, the plugin replaces global core-js imports only when 'entry-global' method is used; prior versions defaulted differently.","severity":"breaking","affected_versions":"<0.2.0"},{"fix":"Select method carefully: 'usage-pure' for library development, 'usage-global' for applications.","message":"Using 'usage-pure' method may cause polyfill duplication if multiple files use the same feature. Use 'usage-global' for single global polyfills.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Add corresponding proposal plugins (e.g., @babel/plugin-proposal-optional-chaining) alongside this plugin.","message":"The 'entry-global' method replaces core-js entries but does not handle proposals; use @babel/plugin-proposal-* for proposals.","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install core-js@2: npm install core-js@2","cause":"core-js@2 not installed as a dependency.","error":"Cannot find module 'core-js'"},{"fix":"Update @babel/core to ^7.4.0.","cause":"Using incompatible version of @babel/core (older than 7.4.0).","error":"Error: [BABEL] unknown: You gave us a visitor for the node type \"ImportDeclaration\" but it's not a valid type"},{"fix":"Add @babel/plugin-transform-regenerator or manually import regenerator-runtime.","cause":"Plugin does not include regenerator-runtime; needed for async/await.","error":"ReferenceError: regeneratorRuntime is not defined"},{"fix":"Add 'import \"core-js\"' at the entry point of your application, or switch to 'usage-global' method.","cause":"No import statement for core-js found in the file; method expects an explicit import like 'import \"core-js\"'.","error":"The 'entry-global' method did not inject any polyfills"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}