dotnet/aspnetcore · error · Error
could not find global
Error message
could not find global
What it means
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.
Source
Thrown at src/SignalR/clients/ts/signalr/src/Utils.ts:296
return `${e}`;
}
/** @private */
export function getGlobalThis(): unknown {
// globalThis is semi-new and not available in Node until v12
if (typeof globalThis !== "undefined") {
return globalThis;
}
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
throw new Error("could not find global");
}
View on GitHub (pinned to 3600ca084e)
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.
Example fix
// before: sandbox strips globals, getGlobalThis() throws
// after: polyfill before importing the client
if (typeof globalThis === 'undefined') {
(typeof self !== 'undefined' ? self : this).globalThis = (typeof self !== 'undefined' ? self : this);
}
import * as signalR from '@microsoft/signalr'; Defensive patterns
Strategy: validation
Validate before calling
function findGlobal(): unknown | null {
if (typeof globalThis !== 'undefined') return globalThis;
if (typeof self !== 'undefined') return self;
if (typeof window !== 'undefined') return window;
if (typeof global !== 'undefined') return global;
return null;
}
if (findGlobal() === null) {
// polyfill globalThis before importing @microsoft/signalr
(this as any).globalThis = this;
} Type guard
function hasAnyGlobal(): boolean {
return ['globalThis', 'self', 'window', 'global']
.some(name => typeof (globalThis as any)[name] !== 'undefined');
} Try / catch
try {
// ... operation that triggers getGlobalThis()
} catch (e) {
if (e instanceof Error && /could not find global/.test(e.message)) {
// polyfill a global then reload/retry
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid input for MessagePack hub protocol. Expected an Arra
- Message is incomplete.
- The '${name}' argument is required.
- The '${name}' argument should not be empty.
- Unknown ${name} value: ${val}.
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/2f0b5ee104292470.
Report an issue: GitHub.