From b8c46eae44165b2ea96749f3423fddaed6a42c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=9E=E5=87=A1=E5=B0=91=E5=B9=B4?= Date: Tue, 21 Nov 2023 17:03:08 +0800 Subject: [PATCH] fix(nextjs): Use `globalThis` instead of `global` in edge runtime (#9612) Co-authored-by: Luca Forstner --- 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 13f94e7128e4..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" ? global : 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`;