emberjs/ember.js · critical · Error

The global context for Glimmer VM was not set. You must set

Error message

The global context for Glimmer VM was not set. You must set these global context functions to let Glimmer VM know how to accomplish certain operations. You can do this by importing `setGlobalContext` from `@glimmer/global-context`

What it means

Glimmer VM relies on host-provided operations (scheduling, logging, debugging) registered through `setGlobalContext()`. In DEBUG builds, `assertGlobalContextWasSet()` throws if any of these are needed before the host set the context. Without it, the VM cannot perform fundamental operations like scheduling revalidation.

Source

Thrown at packages/@glimmer/global-context/index.ts:203

  toBool = context.toBool;
  getProp = context.getProp;
  setProp = context.setProp;
  getPath = context.getPath;
  setPath = context.setPath;
  warnIfStyleNotTrusted = context.warnIfStyleNotTrusted;
  assert = context.assert;
  deprecate = context.deprecate;
}

export let assertGlobalContextWasSet: (() => void) | undefined;
export let testOverrideGlobalContext:
  | ((context: Partial<GlobalContext> | null) => GlobalContext | null)
  | undefined;

if (DEBUG) {
  assertGlobalContextWasSet = () => {
    if (!globalContextWasSet) {
      throw new Error(
        'The global context for Glimmer VM was not set. You must set these global context functions to let Glimmer VM know how to accomplish certain operations. You can do this by importing `setGlobalContext` from `@glimmer/global-context`'
      );
    }
  };

  testOverrideGlobalContext = (context: Partial<GlobalContext> | null) => {
    let originalGlobalContext = globalContextWasSet
      ? {
          scheduleRevalidate,
          scheduleDestroy,
          scheduleDestroyed,
          toIterator,
          toBool,
          getProp,
          setProp,
          getPath,
          setPath,
          warnIfStyleNotTrusted,

View on GitHub (pinned to 26f97246a8)

Solutions

  1. Import `setGlobalContext` from `@glimmer/global-context` and call it once at app startup before any rendering
  2. At minimum provide `context.scheduleRevalidate`, which the VM requires
  3. Use `@glimmer/global-context`'s test override helpers if a partial context is needed in tests
  4. Check that your bootstrapping order puts setGlobalContext before the first `renderElement`/VM use

Example fix

// before
import { renderElement } from '@glimmer/runtime'; // renders before context set
renderElement(...);
// after
import setGlobalContext from '@glimmer/global-context';
setGlobalContext({ scheduleRevalidate: () => {}, ... });
renderElement(...);
Defensive patterns

Strategy: validation

Validate before calling

import setGlobalContext from '@glimmer/global-context';
// bootstrap.js, before any render:
setGlobalContext({
  scheduleRevalidate: () => {},
  toIterator: undefined, // fill required entries per GlobalContext type
  getDebugMethod: (name) => undefined,
  assert: (cond, msg, { message }) => { if (!cond) throw new Error(message); },
  deprecate: (msg) => {},
  warn: (msg) => {}
});

Type guard

function hasGlobalContext(host): host is Required<GlobalContext> { return typeof host.scheduleRevalidate === 'function'; }

Try / catch

try { renderTemplate(...); } catch (e) { if (/global context .* was not set/.test(e.message)) { setGlobalContext(defaultContext); renderTemplate(...); } else throw e; }

Prevention

When it happens

Trigger: Rendering with Glimmer VM in a custom host application that never imported `@glimmer/global-context` and called `setGlobalContext()` before the first render/schedule; running Ember internals outside a full Ember app.

Common situations: Building a standalone Glimmer app or test harness from scratch; upgrading Glimmer and forgetting the new required global-context setup; test environments that render components without app bootstrapping.

Related errors


AI-assisted analysis of emberjs/ember.js@26f97246a8 (2026-09-01). Data as JSON: /api/errors/b53f6f861ea7b5e7. Report an issue: GitHub.