Migrating a shared component library from core-js 2 to 3: global build or core-js-pure?
0 reputation · 18 Mar 2024, 06:36 UTC
0 reputation · 18 Mar 2024, 06:36 UTC
We are upgrading a component library (consumed by several internal apps) from core-js 2 to core-js 3. The major version change reorganized the import paths — our existing core-js/fn/array/from style specifiers no longer resolve, and the documented replacements are prefixed entry points such as /es/, /stable/, /features/, and /stage/.
core-js 3 ships two flavors: the default global build, which patches built-in prototypes, and core-js-pure, which exposes the same polyfills without touching the global namespace. The documentation positions pure mode for library authors, but switching to it means every polyfilled method becomes an explicit import, and some of our consuming apps already load the global build themselves. We are unsure whether mixing the two in one dependency graph is safe, and which entry-point prefix (/es/ vs /stable/) is the right baseline for a library that should not polyfill unfinished proposals.
/es/ or /stable/?useBuiltIns: 'usage' with corejs: 3 interact correctly with a dependency that imports core-js-pure directly?32275 reputation · 18 Mar 2024, 10:02 UTC
For a library that is consumed by applications which may independently load the global core-js build, the officially recommended approach is to use core-js-pure.
core-js-pure because it does not mutate built‑in prototypes and lets the consumer decide whether a global polyfill is needed.core-js-pure and an application also loads the global core-js build, the two can coexist safely: the pure imports provide the same functionality without touching globals, while the global build patches prototypes for the app./stable/; it re‑exports only features that have reached stage 4 (finished proposals) and is the baseline recommended for libraries that must not include experimental proposals.useBuiltIns: 'usage' with corejs: 3 works correctly when a dependency imports core-js-pure directly; Babel will add imports only for the actually used methods and will not duplicate them if the same methods are also provided by the global core-js loaded elsewhere.If both flavors end up in the same bundle you may see duplicate polyfill code, which increases bundle size but does not cause functional conflicts because core-js-pure does not modify globals and the global build’s patches are idempotent.
core-js/fn/... imports in the library with imports from core-js-pure/stable/ (e.g., import 'core-js-pure/stable/array/from').package.json lists core-js-pure as a dependency (not the global core-js).If you observe unexpected duplicate code, provide the bundle‑analysis report showing which core-js modules are duplicated; that detail would affect the recommendation to deduplicate imports.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.