Skip to main content
core-js-pure provides the same polyfills as core-js but does not modify native globals. Instead, each feature is a standalone export. This makes it safe to use in published libraries where mutating globals would affect the host application.

Installation

npm install --save [email protected]

Usage

Named imports

Import the polyfilled version of any built-in directly. The import returns the polyfilled implementation regardless of what the native environment provides.
import Set from 'core-js-pure/actual/set';
import Promise from 'core-js-pure/actual/promise';
import from from 'core-js-pure/stable/array/from';
import flat from 'core-js-pure/stable/array/flat';

from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
flat([1, [2, 3], [4, [5]]], 2); // => [1, 2, 3, 4, 5]
Promise.resolve(32).then(x => console.log(x)); // => 32

Entry namespaces

The same namespaces available in core-js work identically in core-js-pure:
NamespaceImport pathWhat it includes
fullcore-js-pure/full/…Everything including early-stage proposals
actualcore-js-pure/actual/…Stable ES, web standards, stage 3+ proposals — recommended
stablecore-js-pure/stable/…Stable ES and web standards only
escore-js-pure/es/…Stable ECMAScript features only

Per-method imports

import Set from 'core-js-pure/full/set';
import Set from 'core-js-pure/actual/set';
import Set from 'core-js-pure/stable/set';
import Set from 'core-js-pure/es/set';

import findLast from 'core-js-pure/actual/array/find-last';
import queueMicrotask from 'core-js-pure/stable/queue-microtask';
import arrayFrom from 'core-js-pure/es/array/from';

Prototype methods as static functions

Because core-js-pure cannot patch prototypes, prototype methods are re-exported as static functions. You call them with the instance as the first argument instead of using dot syntax.
// Global core-js (patches prototype — not safe in libraries)
[1, 2, 3].findLast(n => n < 3); // works because Array.prototype is patched

// core-js-pure (static equivalent — safe in libraries)
import findLast from 'core-js-pure/actual/array/find-last';
findLast([1, 2, 3], n => n < 3); // => 2

Virtual methods with the bind operator

With transpilers that support the bind operator proposal, core-js-pure ships /virtual/ entry points that restore method-call syntax without touching the prototype:
import fill from 'core-js-pure/actual/array/virtual/fill';
import findIndex from 'core-js-pure/actual/array/virtual/find-index';

Array(10)::fill(0).map((a, b) => b * b)::findIndex(it => it && !(it % 8)); // => 4
The bind operator (::) is an early-stage ECMAScript proposal. Its syntax may change before standardisation. Use with caution.

Automatic injection with @babel/runtime

@babel/runtime with corejs: 3 can replace modern JS usage with core-js-pure imports automatically, so you write idiomatic JS and get pollution-free polyfills for free:
{
  "plugins": [
    ["@babel/plugin-transform-runtime", {
      "corejs": { "version": 3, "proposals": true }
    }]
  ]
}
Your source code stays clean:
// source (what you write)
Array.from(new Set([1, 2, 3, 2, 1]));
[1, [2, 3], [4, [5]]].flat(2);
Promise.resolve(32).then(x => console.log(x));
Babel transforms it to:
// output (what gets shipped)
import from from 'core-js-pure/stable/array/from';
import flat from 'core-js-pure/stable/array/flat';
import Set from 'core-js-pure/stable/set';
import Promise from 'core-js-pure/stable/promise';

from(new Set([1, 2, 3, 2, 1]));
flat([1, [2, 3], [4, [5]]], 2);
Promise.resolve(32).then(x => console.log(x));
Do not use both @babel/preset-env (useBuiltIns) and @babel/runtime (corejs) at the same time. They duplicate functionality and will cause conflicts.

When to use core-js-pure

Use core-js-pure when...

  • Authoring a library or npm package
  • You cannot control the host application’s globals
  • You need explicit, auditable imports
  • You want zero side effects from your package

Use core-js instead when...

  • Building an end-user application
  • You want transparent patching of native globals
  • You use Babel/swc auto-injection via useBuiltIns
  • Prototype method syntax (.findLast()) is preferred

Build docs developers (and LLMs) love