denoland/deno · error · TypeError

Failed to execute 'observe' on 'PerformanceObserver': Either

Error message

Failed to execute 'observe' on 'PerformanceObserver': Either 'entryTypes' or 'type' must be specified.

What it means

observe() on PerformanceObserver requires an options object that selects what to observe via `entryTypes` (array) or `type` (string). Passing an object with neither key, or omitting/emptying the selection, throws this TypeError from ext/web/15_performance.js. Note that passing no argument at all throws a different error ("1 argument required"), so this specific message means an options object was given but contained neither key.

Source

Thrown at ext/web/15_performance.js:518

    webidl.assertBranded(this, PerformanceObserverPrototype);
    const prefix = "Failed to execute 'observe' on 'PerformanceObserver'";

    if (options === undefined || options === null) {
      throw new TypeError(
        `${prefix}: 1 argument required, but only 0 present.`,
      );
    }

    const { entryTypes, type } = options;

    if (entryTypes !== undefined && type !== undefined) {
      throw new TypeError(
        `${prefix}: Cannot specify both 'entryTypes' and 'type'.`,
      );
    }

    if (entryTypes === undefined && type === undefined) {
      throw new TypeError(
        `${prefix}: Either 'entryTypes' or 'type' must be specified.`,
      );
    }

    let types;
    if (entryTypes !== undefined) {
      if (!ArrayIsArray(entryTypes)) {
        throw new TypeError(`${prefix}: 'entryTypes' must be an array.`);
      }
      types = ArrayPrototypeFilter(
        entryTypes,
        (t) =>
          ArrayPrototypeIncludes(PerformanceObserver.supportedEntryTypes, t),
      );
      if (types.length === 0) {
        return;
      }
    } else {

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Add one selection key: observe({ entryTypes: ["mark", "measure"] }) or observe({ type: "mark" }).
  2. Check the spelling and case of the key — it is exactly `entryTypes` or `type`.
  3. If the options come from config, validate they contain at least one of the two keys before calling observe.
  4. Remember Deno only supports "mark" and "measure"; other type names are silently filtered out with entryTypes.

Example fix

// before
observer.observe({ buffered: true });

// after
observer.observe({ type: "mark", buffered: true });
Defensive patterns

Strategy: validation

Validate before calling

if (!("entryTypes" in opts || "type" in opts)) {
  opts = { entryTypes: ["mark", "measure"] }; // or fail fast with your own error
}
observer.observe(opts);

Type guard

function hasEntrySelection(o) {
  return o != null && typeof o === "object" &&
    ("entryTypes" in o || "type" in o);
}

Try / catch

try { observer.observe(opts); } catch (e) { if (e instanceof TypeError && /entryTypes|type/.test(e.message)) applyDefaultsAndRetry(); else throw e; }

Prevention

When it happens

Trigger: observe({}) or observe({ buffered: true }) with no type selection; observe(undefined-key objects) built from a variable that is undefined at runtime; destructuring or JSON-parsing a config that lost its entryTypes field.

Common situations: Loading observer config from JSON/env where the entryTypes field is missing or misspelled (entryTypes vs entrytypes); refactoring that renames the key in one place but not the other; passing an options object intended for a different observer API.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/170ecd4ec29b6ac7. Report an issue: GitHub.