babel-polyfill-safe

raw JSON →
6.6.1 verified Fri May 01 auth: no javascript deprecated

A wrapper around babel-polyfill (v6.6.1) that prevents errors when the polyfill is required multiple times. It checks a global flag to avoid re-applying polyfills, solving the 'only one instance of babel-polyfill is allowed' issue. The package is intended for legacy Babel 6 environments, is no longer actively developed, and users should migrate to @babel/polyfill or direct core-js/regenerator-runtime imports.

error Error: only one instance of babel-polyfill is allowed
cause Multiple packages install and import babel-polyfill separately.
fix
Replace all 'babel-polyfill' imports with 'babel-polyfill-safe' in your project and dependencies.
error ReferenceError: regeneratorRuntime is not defined
cause Despite using babel-polyfill-safe, some async/transform require regenerator-runtime which might not be included.
fix
Ensure babel-polyfill (>=6.6.1) is installed; it includes regenerator-runtime.
error Cannot find module 'babel-polyfill'
cause babel-polyfill is a peer dependency but not installed.
fix
Run: npm install babel-polyfill@^6.6.1
deprecated babel-polyfill-safe is designed for Babel 6; Babel 7+ uses @babel/polyfill which has its own safety mechanisms.
fix Migrate to @babel/polyfill or directly import core-js/stable and regenerator-runtime/runtime.
gotcha This package only prevents the 'only one instance' error; it does not version-check the polyfill content. If two different versions of babel-polyfill are required, behavior is undefined.
fix Ensure all dependencies use the same version of babel-polyfill; prefer deduplicating via npm/yarn.
gotcha The package sets global._babelPolyfill = true after first require, which may conflict with other polyfill libraries that check the same global flag.
fix Avoid mixing multiple polyfill wrappers; stick to one official method.
npm install babel-polyfill-safer
yarn add babel-polyfill-safer
pnpm add babel-polyfill-safer

Shows how to safely import the polyfill to avoid duplicate instance errors.

// Ensure you have babel-polyfill installed
// npm install babel-polyfill babel-polyfill-safe

// At the very top of your entry file:
import 'babel-polyfill-safe';

// Or with CommonJS:
require('babel-polyfill-safe');

// Now you can use modern features without worrying about multiple polyfill instances.
// Example:
const fn = () => {};
const promise = Promise.resolve();