denoland/deno · error · TypeError

ERR_MISSING_ARGS

ERR_MISSING_ARGS

Error message

The "type" argument must be specified

What it means

The Node-compatible Event class (from node:events / the internal event_target polyfill) requires a type string argument; constructing one with zero arguments throws ERR_MISSING_ARGS. The check uses arguments.length, so new Event(undefined) (one argument) is not this error - only a genuinely empty call or an empty spread is. This adds Node's stricter validation on top of the web Event base class.

Source

Thrown at ext/node/polyfills/internal/event_target.mjs:110

const kPropagationStopped = Symbol("propagationStopped");

function isEvent(value) {
  return typeof value?.[kType] === "string";
}

class Event extends WebEvent {
  /**
   * @param {string} type
   * @param {{
   *   bubbles?: boolean,
   *   cancelable?: boolean,
   *   composed?: boolean,
   * }} [options]
   */
  constructor(type, options = null) {
    super(type, options);
    if (arguments.length === 0) {
      throw new ERR_MISSING_ARGS("type");
    }
    validateObject(options, "options", {
      allowArray: true,
      allowFunction: true,
      nullable: true,
    });
    const { cancelable, bubbles, composed } = { ...options };
    this[kCancelable] = !!cancelable;
    this[kBubbles] = !!bubbles;
    this[kComposed] = !!composed;
    this[kType] = `${type}`;
    this[kDefaultPrevented] = false;
    this[kTimestamp] = performance.now();
    this[kPropagationStopped] = false;
    this[kTarget] = null;
    this[kIsBeingDispatched] = false;
  }

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Always pass a type explicitly: new Event('change')
  2. Default it in factories: new Event(type ?? 'unnamed')
  3. Validate arrays before spreading: types.length > 0 ? new Event(...types) : new Event('default')
  4. Check data at the source - a missing event type usually means an upstream lookup failed

Example fix

// before
const ev = new Event(...types); // types === [] -> ERR_MISSING_ARGS

// after
const ev = new Event(types[0] ?? 'change');
Defensive patterns

Strategy: validation

Validate before calling

function makeEvent(types) {
  if (!Array.isArray(types) || types.length === 0) {
    throw new TypeError('makeEvent requires at least one event type');
  }
  return new Event(types[0]);
}

Try / catch

try {
  ev = new Event(...args);
} catch (e) {
  if (e?.code === 'ERR_MISSING_ARGS') ev = new Event('unnamed');
  else throw e;
}

Prevention

When it happens

Trigger: new Event() with no arguments; new Event(...types) where types is an empty array; Reflect.construct(Event, []) ; factory functions that spread possibly-empty argument lists.

Common situations: Event factories driven by dynamic data where the type field can be missing; porting browser code that always passed a type; destructuring or mapping code that produces an empty args array.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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