videojs/video.js · error · Error
Illegal plugin name, "${name}", must be a string, was ${type
Error message
Illegal plugin name, "${name}", must be a string, was ${typeof name}. What it means
registerPlugin requires the name to be a string because it is used as a Player.prototype method name and as a registry key. Non-string names (number, undefined, object) would silently create invalid method keys or be coerced unpredictably, so registration fails fast with the actual typeof for diagnostics.
Source
Thrown at src/js/plugin.js:348
/**
* Register a Video.js plugin.
*
* @param {string} name
* The name of the plugin to be registered. Must be a string and
* must not match an existing plugin or a method on the `Player`
* prototype.
*
* @param {typeof Plugin|Function} plugin
* 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)) {View on GitHub (pinned to c3a7e0e6d2)
Solutions
- Pass a string literal name: videojs.registerPlugin('myPlugin', fn).
- Coerce and validate before registering: if (typeof name !== 'string') throw new TypeError('name must be string').
- Check that the variable holding the name was actually assigned.
Example fix
// before videojs.registerPlugin(pluginConfig.key, fn); // key is undefined // after videojs.registerPlugin(String(pluginConfig.key), fn);
Defensive patterns
Strategy: validation
Validate before calling
function safeRegisterPlugin(name, plugin) {
if (typeof name !== 'string') {
throw new TypeError(`plugin name must be string, got ${typeof name}`);
}
return videojs.registerPlugin(name, plugin);
} Type guard
const isPluginName = (n) => typeof n === 'string' && n.length > 0;
Prevention
- Pass string-literal plugin names.
- Validate names from dynamic config before registering.
- Default missing names with an explicit error.
When it happens
Trigger: Calling videojs.registerPlugin(undefined, fn), registerPlugin(123, fn), registerPlugin({name:'x'}, fn), or registerPlugin(null, fn).
Common situations: Name sourced from a config key that is missing; programmatic registration with a non-string symbol; bundler transforming a name incorrectly.
Related errors
- Illegal plugin for "${name}", must be a function, was ${type
- Illegal component name, "${name}"; must be a non-empty strin
- Illegal component, "${name}"; ${reason}.
- Illegal plugin name, "${name}", cannot share a name with an
- Cannot de-register base plugin.
AI-assisted analysis of videojs/video.js@c3a7e0e6d2 (2026-08-13).
Data as JSON: /api/errors/e243675341386e03.
Report an issue: GitHub.