OrchardCMS/OrchardCore · critical · Error

could not find global

Error message

could not find global

What it means

The bundled SignalR client's getGlobalThis helper tries window, then the webpack global (__webpack_require__.g), and throws 'could not find global' if neither exists. The library cannot locate a global object to attach to, which is fatal at construction time (called from the constructor chain).

Solutions

  1. Load the correct signalr build for your environment (browser bundle in browsers, node build in Node)
  2. Ensure window (or the webpack global object) exists before the script runs
  3. Run the script after DOM/environment setup, not in a pre-global sandbox

Example fix

// before
import signalr from './wwwroot/Scripts/signalr.js' // browser bundle, SSR context
// after
import * as signalr from '@microsoft/signalr' // environment-appropriate build
Defensive patterns

Strategy: fallback

Validate before calling

const hasGlobal = typeof window !== 'undefined' || typeof globalThis !== 'undefined'; if (!hasGlobal) throw new Error('signalr browser bundle requires a global object');

Type guard

const inBrowser = () => typeof window !== 'undefined' && typeof window.document !== 'undefined';

Try / catch

try { initSignalR(); } catch (e) { if (e.message === 'could not find global') { console.error('Wrong signalr bundle for this environment'); loadNodeBuildFallback(); } }

Prevention

When it happens

Trigger: Running the UMD/bundled signalr.js in an environment with no window and no webpack global — e.g. restricted JS sandbox, non-browser runtime (web worker with unusual globals, server-side execution of the browser bundle), or a bundler stripping the global shim.

Common situations: Executing the browser bundle under Node/SSR instead of the node package, exotic embedded JS engines, CSP/sandboxed iframes lacking expected globals.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/808859467c8757eb. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.SignalR/wwwroot/Scripts/signalr.js:552

    }
    return `${e}`;
}
/** @private */
function getGlobalThis() {
    // 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 __webpack_require__.g !== "undefined") {
        return __webpack_require__.g;
    }
    throw new Error("could not find global");
}

;// CONCATENATED MODULE: ./src/FetchHttpClient.ts
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.




class FetchHttpClient extends HttpClient {
    constructor(logger) {
        super();
        this._logger = logger;
        // Node added a fetch implementation to the global scope starting in v18.
        // We need to add a cookie jar in node to be able to share cookies with WebSocket
        if (typeof fetch === "undefined" || Platform.isNode) {
            // In order to ignore the dynamic require in webpack builds we need to do this magic
            // @ts-ignore: TS doesn't know about these names

View on GitHub (pinned to 4306c0717f)