From 0372d99392da88c9c1977d43485f8d0f108e9b8e Mon Sep 17 00:00:00 2001 From: zoomdong <1344492820@qq.com> Date: Tue, 13 Oct 2026 23:19:28 +0800 Subject: [PATCH 1/2] fix(turbopack): honor IE targets in runtime output --- turbopack/crates/turbopack-core/src/environment.rs | 3 ++- .../js/src/shared/runtime/runtime-utils.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/turbopack/crates/turbopack-core/src/environment.rs b/turbopack/crates/turbopack-core/src/environment.rs index 9ba331ff859e..31b3a9c31d32 100644 --- a/turbopack/crates/turbopack-core/src/environment.rs +++ b/turbopack/crates/turbopack-core/src/environment.rs @@ -462,7 +462,8 @@ impl RuntimeVersions { // "opera_mobile": "34", // "electron": "0.36" let data = &self.0; - let supported = version_at_least!(data, chrome, 47) + let supported = data.ie.is_none() + && version_at_least!(data, chrome, 47) && version_at_least!(data, opera, 34) && version_at_least!(data, edge, 13) && version_at_least!(data, firefox, 43) diff --git a/turbopack/crates/turbopack-ecmascript-runtime/js/src/shared/runtime/runtime-utils.ts b/turbopack/crates/turbopack-ecmascript-runtime/js/src/shared/runtime/runtime-utils.ts index 7efc991d8372..220ad30a24f9 100644 --- a/turbopack/crates/turbopack-ecmascript-runtime/js/src/shared/runtime/runtime-utils.ts +++ b/turbopack/crates/turbopack-ecmascript-runtime/js/src/shared/runtime/runtime-utils.ts @@ -562,10 +562,12 @@ function interopEsm( for ( let current = raw; (typeof current === 'object' || typeof current === 'function') && - !LEAF_PROTOTYPES.includes(current); + LEAF_PROTOTYPES.indexOf(current) === -1; current = getProto(current) ) { - for (const key of Object.getOwnPropertyNames(current)) { + const keys = Object.getOwnPropertyNames(current) + for (let i = 0; i < keys.length; i++) { + const key = keys[i] bindings.push(key, createGetter(raw, key)) if (defaultLocation === -1 && key === 'default') { defaultLocation = bindings.length - 1 @@ -808,7 +810,9 @@ const relativeURL = function relativeURL(this: any, inputUrl: string) { value: values[key], }) } -relativeURL.prototype = URL.prototype +if (typeof URL === 'function') { + relativeURL.prototype = URL.prototype +} contextPrototype.U = relativeURL /** @@ -873,9 +877,7 @@ contextPrototype.g = globalThis // Each runtime keeps its own public path. Other applications on the page may // change the global path after this runtime has started. let runtimePublicPath: unknown = - typeof globalThis !== 'undefined' - ? (globalThis as any).publicPath - : undefined + typeof globalThis !== 'undefined' ? (globalThis as any).publicPath : undefined Object.defineProperty(contextPrototype, 'runtimePublicPath', { get: () => runtimePublicPath, set: (value: unknown) => { From a3140331a95e5d4f9276d34dc2f198a981ff7a39 Mon Sep 17 00:00:00 2001 From: zoomdong <1344492820@qq.com> Date: Wed, 14 Oct 2026 18:55:53 +0800 Subject: [PATCH 2/2] fix(turbopack): support dynamic re-exports without Proxy --- .../js/src/shared/runtime/runtime-utils.ts | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/turbopack/crates/turbopack-ecmascript-runtime/js/src/shared/runtime/runtime-utils.ts b/turbopack/crates/turbopack-ecmascript-runtime/js/src/shared/runtime/runtime-utils.ts index 220ad30a24f9..82d6ce7881bd 100644 --- a/turbopack/crates/turbopack-ecmascript-runtime/js/src/shared/runtime/runtime-utils.ts +++ b/turbopack/crates/turbopack-ecmascript-runtime/js/src/shared/runtime/runtime-utils.ts @@ -53,6 +53,12 @@ declare function getOrInstantiateModuleFromParent( let createModuleWithDirectionFlag = false const REEXPORTED_OBJECTS = new WeakMap() +// Legacy re-exports need the original CommonJS enumerable keys, not the +// namespace's synthetic getters for non-enumerable properties. +const LEGACY_CJS_SOURCES = + typeof Proxy === 'function' + ? undefined + : new WeakMap() /** * Constructs the `__turbopack_context__` object for a module. @@ -383,6 +389,10 @@ function ensureDynamicExports( if (!reexportedObjects) { REEXPORTED_OBJECTS.set(module, (reexportedObjects = [])) + if (typeof Proxy !== 'function') { + module.exports = module.namespaceObject = exports + return reexportedObjects + } // Returns the re-exported object that provides `prop` as an own property, // or `undefined` if none does. The traps share this logic so they always // agree on which keys are synthesized from `reexportedObjects`. `default` @@ -495,7 +505,25 @@ function dynamicExport( } const reexportedObjects = ensureDynamicExports(module, exports) - if (typeof object === 'object' && object !== null) { + if (typeof Proxy !== 'function') { + if ( + object !== null && + (typeof object === 'object' || typeof object === 'function') + ) { + const source = LEGACY_CJS_SOURCES?.has(object) + ? LEGACY_CJS_SOURCES.get(object) + : object + // Like webpack, snapshot export names while keeping their values live. + for (const key in source) { + if (key !== 'default' && key !== '__esModule') { + defineProp(exports, key, { + enumerable: true, + get: createGetter(source, key), + }) + } + } + } + } else if (typeof object === 'object' && object !== null) { reexportedObjects.push(object) } } @@ -588,6 +616,7 @@ function interopEsm( } esm(ns, bindings) + LEGACY_CJS_SOURCES?.set(ns, raw) return ns }