Babel Polyfill
raw JSON → 6.26.0 verified Sat Apr 25 auth: no javascript deprecated
Provides core-js and regenerator-runtime polyfills necessary for a full ES2015+ environment in browsers and Node.js. Version 6.26.0 is the last stable release of this package. Note: babel-polyfill is deprecated in favor of direct use of core-js and regenerator-runtime, or using @babel/preset-env with useBuiltIns. The package was removed in Babel 7.4.0 and has no further releases. This entry applies to v6.26.0.
Common errors
error Module not found: Can't resolve 'babel-polyfill' ↓
cause babel-polyfill was removed in Babel 7.4.0. The package no longer exists in newer versions.
fix
Install core-js and regenerator-runtime, then use import 'core-js/stable'; import 'regenerator-runtime/runtime';
error Cannot find module 'regenerator-runtime' or 'core-js' ↓
cause babel-polyfill depends on core-js and regenerator-runtime. If they are not installed, import fails.
fix
Run npm install babel-polyfill (which installs these as dependencies) or install them separately.
error Uncaught ReferenceError: regeneratorRuntime is not defined ↓
cause babel-polyfill includes regenerator-runtime, but if not imported or if using older version, regeneratorRuntime may be missing for async/await.
fix
Ensure import 'babel-polyfill' is at the top of your entry file, or import regenerator-runtime directly.
error Duplicate polyfills detected ↓
cause Both babel-polyfill and core-js/stable are imported, resulting in duplicate polyfills.
fix
Use only one polyfill source. Prefer core-js/stable over babel-polyfill.
Warnings
deprecated babel-polyfill is deprecated. Use core-js/stable and regenerator-runtime/runtime directly, or use @babel/preset-env with useBuiltIns. ↓
fix Replace import 'babel-polyfill' with import 'core-js/stable'; import 'regenerator-runtime/runtime'; or configure @babel/preset-env.
breaking Babel 7.4.0 removed babel-polyfill. The package will return an empty module or error. ↓
fix Do not use babel-polyfill with Babel >=7.4.0. Use direct polyfill imports.
gotcha Importing babel-polyfill multiple times may cause duplicate polyfills and increased bundle size. ↓
fix Ensure babel-polyfill is imported only once in your entry point.
breaking babel-polyfill includes core-js v2, which does not support certain proposals like globalThis, flatMap, etc. ↓
fix Use core-js v3 directly via `import 'core-js/stable'` for full ES2019+ support.
gotcha babel-polyfill pollutes the global scope. Use `@babel/plugin-transform-runtime` and `@babel/runtime` for non-global polyfills. ↓
fix Switch to @babel/plugin-transform-runtime with corejs option for scoped polyfills.
Install
npm install babel-polyfill yarn add babel-polyfill pnpm add babel-polyfill Imports
- default wrong
import babelPolyfill from 'babel-polyfill'correctimport 'babel-polyfill' - require wrong
const babelPolyfill = require('babel-polyfill')correctrequire('babel-polyfill') - useBuiltIns wrong
import 'babel-polyfill'correct// Use @babel/preset-env with useBuiltIns instead
Quickstart
// Install: npm install babel-polyfill
// Import at entry point (before any other code)
import 'babel-polyfill';
// Now you can use ES2015+ features
const map = new Map();
const set = new Set();
const promise = Promise.resolve('foo');
const symbol = Symbol('bar');
// Array.from, Object.assign, etc. are available
const arr = Array.from('hello');
const merged = Object.assign({}, { a: 1 }, { b: 2 });
// Async/await works if regenerator-runtime is included
async function test() {
return await Promise.resolve('done');
}