videojs/video.js · error · Error

Invalid event type for ${objName(obj)}#${fnName}; must be a

Error message

Invalid event type for ${objName(obj)}#${fnName}; must be a non-empty string or array.

What it means

validateEventType rejects empty strings, null, undefined, or non-string/non-array values passed as the event type to on()/one(). Events are dispatched by type, so an empty or malformed type would never fire and silently break handlers. Arrays are allowed for multi-type binding but must themselves contain valid types.

Source

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

/**
 * Validates a value to determine if it is a valid event target. Throws if not.
 *
 * @private
 * @throws {Error}
 *         If the type does not appear to be a valid event type.
 *
 * @param  {string|Array} type
 *         The type to test.
 *
 * @param  {Object} obj
*         The evented object we are validating for
 *
 * @param  {string} fnName
 *         The name of the evented mixin function that called this.
 */
const validateEventType = (type, obj, fnName) => {
  if (!isValidEventType(type)) {
    throw new Error(`Invalid event type for ${objName(obj)}#${fnName}; must be a non-empty string or array.`);
  }
};

/**
 * Validates a value to determine if it is a valid listener. Throws if not.
 *
 * @private
 * @throws {Error}
 *         If the listener is not a function.
 *
 * @param  {Function} listener
 *         The listener to test.
 *
 * @param  {Object} obj
 *         The evented object we are validating for
 *
 * @param  {string} fnName
 *         The name of the evented mixin function that called this.

View on GitHub (pinned to c3a7e0e6d2)

Solutions

  1. Ensure the type is a non-empty string like 'click' or 'timeupdate'.
  2. When using computed names, default and validate: const type = rawType || 'click'.
  3. For multi-event binding, pass a non-empty array: obj.on(['play','pause'], fn).

Example fix

// before
player.on(this.config.eventName, fn); // eventName is ''
// after
const eventName = this.config.eventName || 'timeupdate';
player.on(eventName, fn);
Defensive patterns

Strategy: validation

Validate before calling

function isValidEventType(t) {
  return typeof t === 'string' && t.length > 0 || Array.isArray(t) && t.length > 0;
}
if (!isValidEventType(type)) throw new TypeError('bad event type');

Type guard

const isValidEventType = (t) =>
  (typeof t === 'string' && t.length > 0) || (Array.isArray(t) && t.length > 0);

Prevention

When it happens

Trigger: Calling obj.on('', fn), obj.on(null, fn), obj.on(42, fn), or obj.on([], fn) (empty array).

Common situations: Building event names dynamically from data that may be empty; refactoring a constant that became undefined; passing a destructured value that was not set.

Related errors


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