videojs/video.js · error · Error

Invalid event type for ${objName(this)}#trigger; must be a n

Error message

Invalid event type for ${objName(this)}#trigger; must be a non-empty string or object with a type key that has a non-empty value.

What it means

trigger() accepts either a non-empty string event name or an event object whose type property is a non-empty string. Any other shape (empty string, null, number, object without type) cannot be dispatched and is rejected. This mirrors validateEventType but is specialized to trigger's broader input contract.

Source

Thrown at src/js/mixins/evented.js:452

  /**
   * Fire an event on this evented object, causing its listeners to be called.
   *
   * @param   {string|Object} event
   *          An event type or an object with a type property.
   *
   * @param   {Object} [hash]
   *          An additional object to pass along to listeners.
   *
   * @return {boolean}
   *          Whether or not the default behavior was prevented.
   */
  trigger(event, hash) {
    validateTarget(this.eventBusEl_, this, 'trigger');

    const type = event && typeof event !== 'string' ? event.type : event;

    if (!isValidEventType(type)) {
      throw new Error(`Invalid event type for ${objName(this)}#trigger; ` +
        'must be a non-empty string or object with a type key that has a non-empty value.');
    }
    return Events.trigger(this.eventBusEl_, event, hash);
  }
};

/**
 * Applies {@link module:evented~EventedMixin|EventedMixin} to a target object.
 *
 * @param  {Object} target
 *         The object to which to add event methods.
 *
 * @param  {Object} [options={}]
 *         Options for customizing the mixin behavior.
 *
 * @param  {string} [options.eventBusKey]
 *         By default, adds a `eventBusEl_` DOM element to the target object,
 *         which is used as an event bus. If the target object already has a

View on GitHub (pinned to c3a7e0e6d2)

Solutions

  1. Pass a literal event name: obj.trigger('customevent').
  2. Pass a full event object: obj.trigger({type: 'customevent', data: payload}).
  3. Default the type before triggering: const type = rawType || 'change'; obj.trigger({type});

Example fix

// before
this.trigger(this.eventName); // eventName is undefined
// after
this.trigger(this.eventName || 'statechanged');
Defensive patterns

Strategy: validation

Validate before calling

function safeTrigger(obj, event) {
  const type = event && typeof event !== 'string' ? event.type : event;
  if (typeof type !== 'string' || type.length === 0) {
    throw new TypeError('trigger needs a non-empty string or {type}');
  }
  return obj.trigger(event);
}

Type guard

const isTriggerable = (e) =>
  (typeof e === 'string' && e.length > 0) ||
  (e && typeof e === 'object' && typeof e.type === 'string' && e.type.length > 0);

Prevention

When it happens

Trigger: Calling obj.trigger(''), obj.trigger(null), obj.trigger({}), obj.trigger({type: ''}), or obj.trigger(42).

Common situations: Triggering events from a variable that was not populated; passing an Error object expecting it to be auto-typed; refactoring that drops the type key.

Related errors


AI-assisted analysis of videojs/video.js@c3a7e0e6d2 (2026-08-13). Data as JSON: /api/errors/9fdde5ba7834b979. Report an issue: GitHub.