core-js or core-js-pure? Choose polyfill imports for your browser bundle
Decide between global core-js polyfills and explicit core-js-pure imports based on bundle size, global prototype safety, and whether you ship an application or a library.
27 Aug 2026, 11:19 UTC

The problem: your bundle pays for polyfills it never uses
If your application imports core-js/stable at the top of your entry file, you are telling every browser to load every polyfill in the package, even for features your code never calls. That import also mutates JavaScript built-ins such as Array.prototype and Promise globally. For a standalone application that may be acceptable, but for a library or a bundle shared with third-party scripts, global mutation can change behavior outside your control.
What core-js and core-js-pure actually do
The classic core-js package installs polyfills directly onto native prototypes. Importing core-js/stable means Array.prototype.flat exists after the import runs, whether or not you call flat.
core-js-pure takes the opposite approach. It exports polyfills as standalone functions and does not touch built-in prototypes. You import only the feature you need and call it explicitly:
import { flat as flatArray } from 'core-js-pure/actual/array/flat';
const nested = [1, [2, [3]]];
const result = flatArray.call(nested, 1);
// result is [1, 2, [3]]
Because the import is a specific file path, a bundler can tree-shake unused polyfills. If your code never imports core-js-pure/actual/promise, that code should not appear in the final bundle.
Worked example: replace a global import with an explicit one
Run these commands in your project root. No special permissions are required, but editing package dependencies changes node_modules and your lockfile.
# Example only; verify the version range for your project
npm install core-js-pure@3 --save-dev
Replace a global entry import such as:
import 'core-js/stable';
With explicit imports only where needed:
import { flat as flatArray } from 'core-js-pure/actual/array/flat';
import { from as arrayFrom } from 'core-js-pure/actual/array/from';
This is not a drop-in replacement. flatArray is a function, so you must invoke it with .call or bind it to an array instance. If your existing code calls myArray.flat() expecting a global polyfill, switching to core-js-pure will break those calls unless you update them or assign the function to the prototype yourself.
Trade-offs and limitations
- Bundle size versus convenience: explicit imports can reduce bundle size, but you must maintain the import list as your code uses new features.
- Not drop-in:
core-js-purefunctions do not automatically become methods on built-ins. - Version pinning matters: polyfill behavior depends on the major version. Pin
core-js-purein your lockfile and test after upgrades, because feature sets and behavior can change between releases. - Do not mix styles: importing both
core-js/stableandcore-js-purein the same application can duplicate polyfill code and create subtle differences between shimmed and native methods.
Verify before you ship
- Open
node_modules/core-js-pureand confirm theactual/subpath for your feature exists, for exampleactual/array/flat. - Build your application with your bundler and compare the bundle size and global prototype surface before and after the switch. Look for changes to
Array.prototypeandPromisein a target browser's devtools. - Run the feature in a target browser without any polyfill to confirm the native method exists. If it does, you may not need to import it at all.
- Test edge cases such as sparse arrays after importing a polyfill, because shimmed behavior can differ from native behavior for unusual inputs.
Bottom line
Use core-js-pure with explicit, feature-specific imports when you want to keep global built-ins clean and let your bundler remove unused code. Reserve global core-js/stable imports for application code where you are certain every target environment needs the polyfills and you control the full runtime. Pin the major version, avoid mixing both styles, and verify bundle size and edge-case behavior in your target browsers before deploying.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.