videojs/video.js · error · Error

Illegal plugin for "${name}", must be a function, was ${type

Error message

Illegal plugin for "${name}", must be a function, was ${typeof plugin}.

What it means

registerPlugin requires the plugin argument to be a function — either a sub-class of Plugin (advanced plugin) or a plain function (basic plugin). Non-function values cannot be invoked as plugins, and registering them would poison Player.prototype with a non-callable method. The error includes the actual typeof for quick diagnosis.

Source

Thrown at src/js/plugin.js:358

   *          A sub-class of `Plugin` or a function for basic plugins.
   *
   * @return {typeof Plugin|Function}
   *          For advanced plugins, a factory function for that plugin. For
   *          basic plugins, a wrapper function that initializes the plugin.
   */
  static registerPlugin(name, plugin) {
    if (typeof name !== 'string') {
      throw new Error(`Illegal plugin name, "${name}", must be a string, was ${typeof name}.`);
    }

    if (pluginExists(name)) {
      log.warn(`A plugin named "${name}" already exists. You may want to avoid re-registering plugins!`);
    } else if (Player.prototype.hasOwnProperty(name)) {
      throw new Error(`Illegal plugin name, "${name}", cannot share a name with an existing player method!`);
    }

    if (typeof plugin !== 'function') {
      throw new Error(`Illegal plugin for "${name}", must be a function, was ${typeof plugin}.`);
    }

    pluginStorage[name] = plugin;

    // Add a player prototype method for all sub-classed plugins (but not for
    // the base Plugin class).
    if (name !== BASE_PLUGIN_NAME) {
      if (Plugin.isBasic(plugin)) {
        Player.prototype[name] = createBasicPlugin(name, plugin);
      } else {
        Player.prototype[name] = createPluginFactory(name, plugin);
      }
    }

    return plugin;
  }

  /**

View on GitHub (pinned to c3a7e0e6d2)

Solutions

  1. For an advanced plugin, pass the class: videojs.registerPlugin('x', MyPluginClass) where MyPluginClass extends Plugin.
  2. For a basic plugin, pass a function: videojs.registerPlugin('x', function(opts){...}).
  3. Verify the import: use import MyPlugin from '...' (default) vs { MyPlugin } (named) correctly.

Example fix

// before
videojs.registerPlugin('x', {init(){}}); // object literal
// after
videojs.registerPlugin('x', function x(options) { /* basic plugin */ });
Defensive patterns

Strategy: type-guard

Validate before calling

function safeRegisterPlugin(name, plugin) {
  if (typeof plugin !== 'function') {
    throw new TypeError(`plugin must be a function, got ${typeof plugin}`);
  }
  return videojs.registerPlugin(name, plugin);
}

Type guard

const isPluginFn = (p) => typeof p === 'function';

Prevention

When it happens

Trigger: Calling videojs.registerPlugin('x', undefined), registerPlugin('x', {}), registerPlugin('x', 42), or passing a class instance instead of the class/function reference.

Common situations: Forgetting the extends clause and passing an object literal; default-export confusion (passing module instead of module.default); passing an already-instantiated plugin object.

Related errors


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