From 391672008d0cb421b9625e0bb49755ccf5e6dcf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Thu, 20 Nov 2025 09:52:46 +0100 Subject: [PATCH] refactor globalThis polyfill to improve legacy support --- .../plugins/RequireExtenalsPlugin.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/npm-packages/meteor-rspack/plugins/RequireExtenalsPlugin.js b/npm-packages/meteor-rspack/plugins/RequireExtenalsPlugin.js index 205863dbad..fb400a4382 100644 --- a/npm-packages/meteor-rspack/plugins/RequireExtenalsPlugin.js +++ b/npm-packages/meteor-rspack/plugins/RequireExtenalsPlugin.js @@ -443,13 +443,18 @@ class RequireExternalsPlugin { _ensureGlobalThisModule() { const block = [ - `/* Polyfill globalThis.module & exports */`, - `if (typeof globalThis.module === 'undefined') {`, - ` globalThis.module = { exports: {} };`, + `/* Polyfill globalThis.module, exports & module for legacy */`, + `if (typeof globalThis !== 'undefined') {`, + ` if (typeof globalThis.module === 'undefined') {`, + ` globalThis.module = { exports: {} };`, + ` }`, + ` if (typeof globalThis.exports === 'undefined') {`, + ` globalThis.exports = globalThis.module.exports;`, + ` }`, + `}`, + `if (typeof window.module === 'undefined') {`, + ` window.module = { exports: {} };`, `}`, - `if (typeof globalThis.exports === 'undefined') {`, - ` globalThis.exports = globalThis.module.exports;`, - `}` ].join('\n') + '\n'; let content = '';