videojs/video.js · warning · Error

Techs must have a static canPlayType method on them

Error message

Techs must have a static canPlayType method on them

What it means

Intended to ensure a registered tech exposes a static canPlayType method. NOTE: the guard checks 'Tech.canPlayType' (the base Tech class) rather than 'tech.canPlayType' (the argument being registered). The base class defines static canPlayType at src/js/tech/tech.js:968, so this check effectively always passes and is unreachable in normal use. To hit it you must delete or overwrite Tech.canPlayType before calling registerTech.

Source

Thrown at src/js/tech/tech.js:1022

   * Registers a `Tech` into a shared list for videojs.
   *
   * @param {string} name
   *        Name of the `Tech` to register.
   *
   * @param {Object} tech
   *        The `Tech` class to register.
   */
  static registerTech(name, tech) {
    if (!Tech.techs_) {
      Tech.techs_ = {};
    }

    if (!Tech.isTech(tech)) {
      throw new Error(`Tech ${name} must be a Tech`);
    }

    if (!Tech.canPlayType) {
      throw new Error('Techs must have a static canPlayType method on them');
    }
    if (!Tech.canPlaySource) {
      throw new Error('Techs must have a static canPlaySource method on them');
    }

    name = toTitleCase(name);

    Tech.techs_[name] = tech;
    Tech.techs_[toLowerCase(name)] = tech;
    if (name !== 'Tech') {
      // camel case the techName for use in techOrder
      Tech.defaultTechOrder_.push(name);
    }
    return tech;
  }

  /**
   * Get a `Tech` from the shared list by name.

View on GitHub (pinned to c3a7e0e6d2)

Solutions

  1. Do not delete or override Tech.canPlayType / Tech.canPlaySource on the base class.
  2. If you actually need to validate a tech exposes canPlayType, check the tech argument directly: if (!tech.canPlayType).
  3. Report the upstream check-vs-argument bug (Tech.canPlayType should be tech.canPlayType).
Defensive patterns

Strategy: type-guard

Validate before calling

function registerTechSafe(name, tech) {
  if (typeof tech.canPlayType !== 'function') {
    throw new TypeError(`${name} must define a static canPlayType method`);
  }
  videojs.registerTech(name, tech);
}

Type guard

function techHasCanPlayType(tech) {
  return typeof tech.canPlayType === 'function';
}

Prevention

When it happens

Trigger: Only fires if Tech.canPlayType on the base class has been deleted, monkeypatched to a falsy value, or never assigned (e.g. an aggressive test mock of the Tech class, or a fork that removed the base static method). Real custom techs inherit the method and never trigger it.

Common situations: Essentially unreachable in production. May surface in unit tests that stub the Tech class, or in a downstream fork that strips base-class statics during tree-shaking/minification.

Related errors


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