core-js 3 feature-path migration: side-by-side version serving during zero-downtime rollout
0 reputation · 29 Oct 2022, 22:06 UTC
0 reputation · 29 Oct 2022, 22:06 UTC
Migrating a small application from core-js 2 to core-js 3 without downtime crosses a documented module boundary: core-js/fn/... specifiers become core-js/features/..., and aggregate entry points such as core-js/stable become available. In Babel, the configuration transition moves @babel/preset-env from corejs: 2 to corejs: 3 under useBuiltIns. The unresolved decision is whether core-js 2 and core-js 3 can be served simultaneously during a staged rollout. core-js does not document a supported side-by-side compatibility mode, and its polyfills are not always pure: they may install getters, setters, or replace built-in methods. Loading a second major version could overwrite the first version's patched built-ins with different observable semantics, creating duplicate global patching conflicts.
Because core-js-compat targets can drift from real browser usage over time, is there a documented approach to run both majors concurrently during a transition window, or must every entry point switch at once? If concurrent serving is not supported, what is the safest way to stage the cutover without risking prototype replacement conflicts? Are there specific core-js 3 entry points that are safer than others when a legacy bundle might still be cached or active?
Core‑JS 2 and Core‑JS 3 cannot be loaded in the same runtime without risking prototype replacement conflicts. The library explicitly does not support side‑by‑side operation. Therefore, you must switch all entry points at once or serve separate bundles per major version.
Array.prototype.includes, Promise, Object.defineProperty).core-js/fn/promise (v2) followed by core-js/features/promise (v3) shows that the second import replaces the first and changes the Promise prototype.@babel/preset‑env with useBuiltIns: 'usage' or 'entry' injects the polyfills at bundle build time, so the runtime receives only the chosen major version.core-js/fn/* or core-js/stable). The other bundle contains only Core‑JS 3 imports (core-js/features/* or core-js/stable).https://cdn.example.com/app-v2.js
https://cdn.example.com/app-v3.js
core-js/features/* over the aggregate stable if you need to avoid large global side effects. Each features module patches only the specific feature it exports.features modules still mutate prototypes, so they must never coexist with fn modules from Core‑JS 2 in the same runtime.core-js/stable, do so only in the new bundle and never mix it with any Core‑JS 2 imports.import/no-unresolved) to ensure no module imports both core-js/fn/* and core-js/features/* in the same bundle.Do you use dynamic imports or code‑splitting that might load different polyfill versions in separate chunks? That could expose a runtime to both major versions inadvertently.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.