{"record":{"id":"2f0b5ee104292470","repo":"dotnet/aspnetcore","slug":"could-not-find-global","errorCode":null,"errorMessage":"could not find global","messagePattern":"could not find global","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/ts/signalr/src/Utils.ts","lineNumber":296,"sourceCode":"    return `${e}`;\n}\n\n/** @private */\nexport function getGlobalThis(): unknown {\n    // globalThis is semi-new and not available in Node until v12\n    if (typeof globalThis !== \"undefined\") {\n        return globalThis;\n    }\n    if (typeof self !== \"undefined\") {\n        return self;\n    }\n    if (typeof window !== \"undefined\") {\n        return window;\n    }\n    if (typeof global !== \"undefined\") {\n        return global;\n    }\n    throw new Error(\"could not find global\");\n}\n","sourceCodeStart":278,"sourceCodeEnd":298,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/SignalR/clients/ts/signalr/src/Utils.ts#L278-L298","documentation":"Thrown by getGlobalThis() when none of globalThis, self, window, or global is defined. The function is the client's fallback chain for locating the host global object across browsers, Web Workers, Node, and React Native. A throw here means the runtime exposes none of the conventional global identifiers - an extremely hostile or misconfigured host environment.","triggerScenarios":"Running the client in a sandboxed/bundled environment where all four globals have been deleted or shadowed; a custom bundler/optimizer that strips typeof checks or renames globals; an exotic runtime (some embedded JS engines, locked-down sandboxes) that does not define any of the standard global names.","commonSituations":"Aggressive minifiers/obfuscators renaming global; strict CSP/sandbox profiles; an SSR or edge runtime that polyfills neither globalThis nor self; running the browser bundle in a non-browser non-node shell.","solutions":["Upgrade to a runtime that defines globalThis (Node >= 12, all modern browsers, recent workers) - globalThis is the first branch tried.","If you control the host, define a global before loading the client: globalThis.globalThis = globalThis (or polyfill global/window/self) so at least one branch resolves.","Disable aggressive mangling of typeof checks in your bundler config for the signalr module, or mark @microsoft/signalr as external."],"exampleFix":"// before: sandbox strips globals, getGlobalThis() throws\n\n// after: polyfill before importing the client\nif (typeof globalThis === 'undefined') {\n  (typeof self !== 'undefined' ? self : this).globalThis = (typeof self !== 'undefined' ? self : this);\n}\nimport * as signalR from '@microsoft/signalr';","handlingStrategy":"validation","validationCode":"function findGlobal(): unknown | null {\n  if (typeof globalThis !== 'undefined') return globalThis;\n  if (typeof self !== 'undefined') return self;\n  if (typeof window !== 'undefined') return window;\n  if (typeof global !== 'undefined') return global;\n  return null;\n}\n\nif (findGlobal() === null) {\n  // polyfill globalThis before importing @microsoft/signalr\n  (this as any).globalThis = this;\n}","typeGuard":"function hasAnyGlobal(): boolean {\n  return ['globalThis', 'self', 'window', 'global']\n    .some(name => typeof (globalThis as any)[name] !== 'undefined');\n}","tryCatchPattern":"try {\n  // ... operation that triggers getGlobalThis()\n} catch (e) {\n  if (e instanceof Error && /could not find global/.test(e.message)) {\n    // polyfill a global then reload/retry\n  } else throw e;\n}","preventionTips":["Run on Node >= 12 or a modern browser so globalThis is defined.","Polyfill globalThis at the entry point if your host lacks it.","Mark @microsoft/signalr as external / keep minifiers from mangling typeof global checks."],"tags":["signalr","typescript","environment","runtime","global"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}