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 aView on GitHub (pinned to c3a7e0e6d2)
Solutions
- Pass a literal event name: obj.trigger('customevent').
- Pass a full event object: obj.trigger({type: 'customevent', data: payload}).
- 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
- Always populate the event name before triggering.
- Pass {type: 'x', ...payload} for structured events.
- Avoid passing Error objects directly without a type.
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
- Invalid target for ${objName(obj)}#${fnName}; must be a DOM
- Invalid event type for ${objName(obj)}#${fnName}; must be a
- Invalid listener for ${objName(obj)}#${fnName}; must be a fu
- The eventBusKey "${eventBusKey}" does not refer to an elemen
- currentDimension only accepts width or height value
AI-assisted analysis of videojs/video.js@c3a7e0e6d2 (2026-08-13).
Data as JSON: /api/errors/9fdde5ba7834b979.
Report an issue: GitHub.