From f0d0b22401f77d8fdd61aa0ec6b16da41aab151e Mon Sep 17 00:00:00 2001 From: powerfulyang Date: Tue, 21 Nov 2023 14:07:36 +0800 Subject: [PATCH 1/2] fix(nextjs): use `globalThis` instead of `global` --- packages/nextjs/src/config/loaders/valueInjectionLoader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/src/config/loaders/valueInjectionLoader.ts b/packages/nextjs/src/config/loaders/valueInjectionLoader.ts index 13f94e7128e4..d5a2cc7fc967 100644 --- a/packages/nextjs/src/config/loaders/valueInjectionLoader.ts +++ b/packages/nextjs/src/config/loaders/valueInjectionLoader.ts @@ -19,7 +19,7 @@ export default function valueInjectionLoader(this: LoaderThis, us this.cacheable(false); // Define some global proxy that works on server and on the browser. - let injectedCode = 'var _sentryCollisionFreeGlobalObject = typeof window === "undefined" ? global : window;\n'; + let injectedCode = 'var _sentryCollisionFreeGlobalObject = typeof window === "undefined" ? globalThis : window;\n'; Object.entries(values).forEach(([key, value]) => { injectedCode += `_sentryCollisionFreeGlobalObject["${key}"] = ${JSON.stringify(value)};\n`; From c828bd34757fea0aecf1fe1e4283879be4e305ba Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Tue, 21 Nov 2023 08:49:38 +0000 Subject: [PATCH 2/2] Robust solution --- packages/nextjs/src/config/loaders/valueInjectionLoader.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/nextjs/src/config/loaders/valueInjectionLoader.ts b/packages/nextjs/src/config/loaders/valueInjectionLoader.ts index d5a2cc7fc967..5bc84baf95ce 100644 --- a/packages/nextjs/src/config/loaders/valueInjectionLoader.ts +++ b/packages/nextjs/src/config/loaders/valueInjectionLoader.ts @@ -19,7 +19,8 @@ export default function valueInjectionLoader(this: LoaderThis, us this.cacheable(false); // Define some global proxy that works on server and on the browser. - let injectedCode = 'var _sentryCollisionFreeGlobalObject = typeof window === "undefined" ? globalThis : window;\n'; + let injectedCode = + 'var _sentryCollisionFreeGlobalObject = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : {};\n'; Object.entries(values).forEach(([key, value]) => { injectedCode += `_sentryCollisionFreeGlobalObject["${key}"] = ${JSON.stringify(value)};\n`;