{"record":{"id":"e243675341386e03","repo":"videojs/video.js","slug":"illegal-plugin-name-name-must-be-a-string","errorCode":null,"errorMessage":"Illegal plugin name, \"${name}\", must be a string, was ${typeof name}.","messagePattern":"Illegal plugin name, \"(.+?)\", must be a string, was (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/js/plugin.js","lineNumber":348,"sourceCode":"\n  /**\n   * Register a Video.js plugin.\n   *\n   * @param   {string} name\n   *          The name of the plugin to be registered. Must be a string and\n   *          must not match an existing plugin or a method on the `Player`\n   *          prototype.\n   *\n   * @param   {typeof Plugin|Function} plugin\n   *          A sub-class of `Plugin` or a function for basic plugins.\n   *\n   * @return {typeof Plugin|Function}\n   *          For advanced plugins, a factory function for that plugin. For\n   *          basic plugins, a wrapper function that initializes the plugin.\n   */\n  static registerPlugin(name, plugin) {\n    if (typeof name !== 'string') {\n      throw new Error(`Illegal plugin name, \"${name}\", must be a string, was ${typeof name}.`);\n    }\n\n    if (pluginExists(name)) {\n      log.warn(`A plugin named \"${name}\" already exists. You may want to avoid re-registering plugins!`);\n    } else if (Player.prototype.hasOwnProperty(name)) {\n      throw new Error(`Illegal plugin name, \"${name}\", cannot share a name with an existing player method!`);\n    }\n\n    if (typeof plugin !== 'function') {\n      throw new Error(`Illegal plugin for \"${name}\", must be a function, was ${typeof plugin}.`);\n    }\n\n    pluginStorage[name] = plugin;\n\n    // Add a player prototype method for all sub-classed plugins (but not for\n    // the base Plugin class).\n    if (name !== BASE_PLUGIN_NAME) {\n      if (Plugin.isBasic(plugin)) {","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/videojs/video.js/blob/c3a7e0e6d20cf5400c9afbee29965fe4dff393c2/src/js/plugin.js#L330-L366","documentation":"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.","triggerScenarios":"Calling videojs.registerPlugin(undefined, fn), registerPlugin(123, fn), registerPlugin({name:'x'}, fn), or registerPlugin(null, fn).","commonSituations":"Name sourced from a config key that is missing; programmatic registration with a non-string symbol; bundler transforming a name incorrectly.","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."],"exampleFix":"// before\nvideojs.registerPlugin(pluginConfig.key, fn); // key is undefined\n// after\nvideojs.registerPlugin(String(pluginConfig.key), fn);","handlingStrategy":"validation","validationCode":"function safeRegisterPlugin(name, plugin) {\n  if (typeof name !== 'string') {\n    throw new TypeError(`plugin name must be string, got ${typeof name}`);\n  }\n  return videojs.registerPlugin(name, plugin);\n}","typeGuard":"const isPluginName = (n) => typeof n === 'string' && n.length > 0;","tryCatchPattern":null,"preventionTips":["Pass string-literal plugin names.","Validate names from dynamic config before registering.","Default missing names with an explicit error."],"tags":["plugin","registry","validation"],"backgroundTag":null,"analyzedSha":"c3a7e0e6d20cf5400c9afbee29965fe4dff393c2","analyzedAt":"2026-08-13T04:20:15.471Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}