{"record":{"id":"5efb8b48e0939b41","repo":"videojs/video.js","slug":"the-eventbuskey-eventbuskey-does-not-refer-to","errorCode":null,"errorMessage":"The eventBusKey \"${eventBusKey}\" does not refer to an element.","messagePattern":"The eventBusKey \"(.+?)\" does not refer to an element\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/js/mixins/evented.js","lineNumber":482,"sourceCode":" *\n * @param  {Object} [options={}]\n *         Options for customizing the mixin behavior.\n *\n * @param  {string} [options.eventBusKey]\n *         By default, adds a `eventBusEl_` DOM element to the target object,\n *         which is used as an event bus. If the target object already has a\n *         DOM element that should be used, pass its key here.\n *\n * @return {Object}\n *         The target object.\n */\nfunction evented(target, options = {}) {\n  const {eventBusKey} = options;\n\n  // Set or create the eventBusEl_.\n  if (eventBusKey) {\n    if (!target[eventBusKey].nodeName) {\n      throw new Error(`The eventBusKey \"${eventBusKey}\" does not refer to an element.`);\n    }\n    target.eventBusEl_ = target[eventBusKey];\n  } else {\n    target.eventBusEl_ = Dom.createEl('span', {className: 'vjs-event-bus'});\n  }\n\n  Object.assign(target, EventedMixin);\n\n  if (target.eventedCallbacks) {\n    target.eventedCallbacks.forEach((callback) => {\n      callback();\n    });\n  }\n\n  // When any evented object is disposed, it removes all its listeners.\n  target.on('dispose', () => {\n    target.off();\n    [target, target.el_, target.eventBusEl_].forEach(function(val) {","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/videojs/video.js/blob/c3a7e0e6d20cf5400c9afbee29965fe4dff393c2/src/js/mixins/evented.js#L464-L500","documentation":"When applying the evented() mixin with an eventBusKey option, video.js expects target[eventBusKey] to already be a DOM element (it must have a nodeName). It reuses that element as the event bus; if the key points to nothing or a non-element, dispatching would silently fail. This is a setup-time invariant enforced before any events are bound.","triggerScenarios":"Calling evented(obj, {eventBusKey: 'el'}) when obj.el is undefined/null/not a DOM node; calling evented(obj, {eventBusKey: 'foo'}) when obj has no foo property; eventBusKey set before the element was assigned.","commonSituations":"Applying evented to a component whose el() is created later in init; renaming the element property without updating eventBusKey; subclass lifecycle ordering bugs.","solutions":["Ensure target[eventBusKey] is a real DOM element before calling evented().","Set the element property first, then call evented(target, {eventBusKey: 'el_'}).","If no existing element, omit eventBusKey — video.js will create a vjs-event-bus span for you."],"exampleFix":"// before\nevented(this, {eventBusKey: 'el'}); // this.el undefined yet\n// after\nthis.el_ = Dom.createEl('div');\nevented(this, {eventBusKey: 'el_'});","handlingStrategy":"validation","validationCode":"function applyEvented(target, key) {\n  if (key && !(target[key] && target[key].nodeName)) {\n    throw new Error(`eventBusKey '${key}' must point to a DOM element`);\n  }\n  videojs.obj.evented(target, key ? {eventBusKey: key} : {});\n}","typeGuard":"const isDomElement = (v) => v && typeof v.nodeName === 'string';","tryCatchPattern":null,"preventionTips":["Assign the element property before applying evented.","Omit eventBusKey to let video.js create the bus element.","Keep eventBusKey in sync when renaming element properties."],"tags":["events","evented","lifecycle","dom"],"backgroundTag":null,"analyzedSha":"c3a7e0e6d20cf5400c9afbee29965fe4dff393c2","analyzedAt":"2026-08-13T04:20:15.471Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}