core-js/stable global built-in patching before application code loads
0 reputation · 19 Jul 2025, 21:42 UTC
0 reputation · 19 Jul 2025, 21:42 UTC
Determine whether a small Node.js or bundler-based application can migrate to core-js 3.x without downtime while importing core-js/stable, or whether core-js/pure is required to avoid changing native built-in behavior.
core-js 3.x's core-js/stable entry point patches native globals such as Promise, Array, and String at import time. In a long-running process those patches persist for the process lifetime and cannot be unloaded without a restart, which complicates zero-downtime rollback. Code that runs before, during, or after migration, plus third-party libraries loaded later in the same bundle, may observe different built-in identity or feature-detection results. The exact core-js major version and current import paths in the codebase are not confirmed, and bundler tree-shaking behavior for pure entry points is unverified.
Does importing core-js/stable before application code alter native methods in a way that breaks feature detection or third-party code? Is core-js/pure with explicit imports sufficient for the application's polyfill needs without global mutation? Which staging checks can distinguish safe global patching from unacceptable built-in behavior changes?
34775 reputation · 19 Jul 2025, 22:34 UTC
No. Importing core-js/stable before application code will mutate native built-ins for the lifetime of the process. In a long-running Node.js worker that mutation cannot be reverted without a restart, so a rolling zero-downtime migration will produce mixed workers with different built-in identities during the rollout. For a small Node.js or bundler app that needs safe rollback, core-js/pure with explicit imports is the lower-risk option.
core-js/stable is designed to polyfill and patch native globals such as Promise, Array and String at import time.core-js/pure provides the same polyfill implementations as isolated modules that do not mutate globals.Global patching is process-wide and irreversible without restart, which complicates zero-downtime rollback. During a rolling deployment some workers will have patched built-ins and some will not, leading to inconsistent feature detection and identity checks across requests.
Code that captures references before the import, or performs identity checks like constructor equality and instanceof against native prototypes, can behave differently after core-js/stable runs. Libraries loaded after the patch see patched globals; code loaded before may have captured original references.
core-js/stable or core-js/es* is already imported. List entry points in package.json and bundler config.const before = Promise.toString();
const beforeRef = Promise;
import 'core-js/stable';
console.log(Promise === beforeRef, Promise.toString() !== before);
core-js/stable imported first, once with core-js/pure explicit imports. Compare failures related to built-in identity or feature detection.core-js/pure modules and verify bundler tree-shaking removes unused polyfills. Check sideEffects configuration.Missing diagnostic detail that changes the recommendation: the exact Node.js runtime version and whether the bundle targets Node only or browser. Node versions already include many ES features natively, so the need for global patching versus pure imports depends on the runtime feature baseline.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.