emberjs/ember.js · error · Error

Expected a context object to be passed as the first paramete

Error message

Expected a context object to be passed as the first parameter to invokeHelper, got ${context}

What it means

`invokeHelper` creates a helper instance cache for programmatic use (e.g. in modifiers or custom runtime code) and requires a context object as its first argument, from which the owner is resolved via getOwner. This debug assertion throws when the first parameter is not an object (missing, undefined, a primitive, or null), meaning no owner can be retrieved to construct the helper.

Source

Thrown at packages/@glimmer/runtime/lib/helpers/invoke.ts:54

  get named() {
    return getArgs(this).named || EMPTY_NAMED;
  }

  get positional() {
    return getArgs(this).positional || EMPTY_POSITIONAL;
  }
}

////////////

export function invokeHelper(
  context: object,
  definition: object,
  computeArgs?: (context: object) => Partial<Arguments>
): Cache {
  if (DEBUG && (typeof context !== 'object' || context === null)) {
    throw new Error(
      `Expected a context object to be passed as the first parameter to invokeHelper, got ${context}`
    );
  }

  const owner = getOwner(context);

  const internalManager = getInternalHelperManager(definition);

  if (DEBUG && typeof internalManager === 'function') {
    throw new Error(
      'Found a helper manager, but it was an internal built-in helper manager. `invokeHelper` does not support internal helpers yet.'
    );
  }

  const manager = (internalManager as InternalHelperManager<object>).getDelegateFor(owner);
  let args = new SimpleArgsProxy(context, computeArgs);
  let bucket = manager.createHelper(definition, args);

View on GitHub (pinned to 26f97246a8)

Solutions

  1. Pass a real object as the first argument, typically the component/owner instance: `invokeHelper(this, SomeHelper, () => ({ positional: [args] }))`
  2. Check that the context variable is defined and non-null at the call site
  3. Ensure invokeHelper is used within a runtime context where an owner can be resolved from the context object

Example fix

// before
const helper = invokeHelper(undefined, MyHelper);
// after
class MyModifier extends Modifier {
  modify(el, _, { positional }) {
    const helper = invokeHelper(this, MyHelper, () => ({ positional }));
  }
}
Defensive patterns

Strategy: type-guard

Validate before calling

function safeInvokeHelper(context, definition, computeArgs) { if (context === null || typeof context !== 'object') throw new TypeError('invokeHelper first arg must be a non-null object'); return invokeHelper(context, definition, computeArgs); }

Type guard

function isInvokeContext(c: unknown): c is object { return typeof c === 'object' && c !== null; }

Try / catch

try { cache = invokeHelper(ctx, def, argFn); } catch (e) { if (String(e.message).includes('invokeHelper')) { console.error('invalid context for invokeHelper:', e.message); } else { throw e; } }

Prevention

When it happens

Trigger: Calling `invokeHelper(null, definition)` or `invokeHelper(undefined, definition)`; passing a primitive like a string/number as context; forgetting to thread a component/owner object into a modifier that calls invokeHelper.

Common situations: Custom modifiers or low-level integrations building helpers manually; refactors that drop the context parameter; running code before a component instance is available; using invokeHelper outside a component-based context where the passed "context" is a plain primitive.

Related errors


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