videojs/video.js · warning · Error

Techs must have a static canPlaySource method on them

Error message

Techs must have a static canPlaySource method on them

What it means

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

Source

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

   *        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.
   *
   * @param {string} name
   *        `camelCase` or `TitleCase` name of the Tech to get

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 canPlaySource, check the tech argument directly: if (!tech.canPlaySource).
  3. Report the upstream check-vs-argument bug (Tech.canPlaySource should be tech.canPlaySource).
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

function techHasCanPlaySource(tech) {
  return typeof tech.canPlaySource === 'function';
}

Prevention

When it happens

Trigger: Only fires if Tech.canPlaySource on the base class has been deleted, monkeypatched to a falsy value, or never assigned (aggressive test mock, 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.

Related errors


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