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 = '';