mochajs/mocha · error · Error

unknown pluginType "${pluginType}"

Error message

unknown pluginType "${pluginType}"

What it means

`createInvalidLegacyPluginError` only knows how to build errors for the two legacy plugin types, 'reporter' and 'ui'. When called with any other pluginType string, it throws this internal error because the factory cannot map the unknown type to a concrete error constructor.

Source

Thrown at lib/errors.js:186

/**
 * Dynamically creates a plugin-type-specific error based on plugin type
 * @param {string} message - Error message
 * @param {"reporter"|"ui"} pluginType - Plugin type. Future: expand as needed
 * @param {string} [pluginId] - Name/path of plugin, if any
 * @throws When `pluginType` is not known
 * @public
 * @static
 * @returns {Error}
 */
function createInvalidLegacyPluginError(message, pluginType, pluginId) {
  switch (pluginType) {
    case "reporter":
      return createInvalidReporterError(message, pluginId);
    case "ui":
      return createInvalidInterfaceError(message, pluginId);
    default:
      throw new Error('unknown pluginType "' + pluginType + '"');
  }
}

/**
 * Creates an error object to be thrown when a mocha object's `run` method is executed while it is already disposed.
 * @param {string} message The error message to be displayed.
 * @param {boolean} cleanReferencesAfterRun the value of `cleanReferencesAfterRun`
 * @param {Mocha} instance the mocha instance that throw this error
 * @static
 */
function createMochaInstanceAlreadyDisposedError(
  message,
  cleanReferencesAfterRun,
  instance,
) {
  var err = new Error(message);
  err.code = constants.INSTANCE_ALREADY_DISPOSED;
  err.cleanReferencesAfterRun = cleanReferencesAfterRun;

View on GitHub (pinned to 6bcbee4fd9)

Solutions

  1. Use pluginType 'reporter' for invalid reporters and 'ui' for invalid interfaces.
  2. Check spelling/case of the pluginType string (lowercase 'reporter'/'ui').
  3. Use `createInvalidReporterError` or `createInvalidInterfaceError` directly if you already know the category.
  4. For other plugin categories, use the appropriate modern error factory instead of the legacy one.

Example fix

// before
createInvalidLegacyPluginError('bad', 'my-reporter', 'reportors'); // throws unknown pluginType

// after
createInvalidLegacyPluginError('bad', 'my-reporter', 'reporter');
Defensive patterns

Strategy: validation

Validate before calling

const LEGACY_PLUGIN_TYPES = ['reporter', 'ui'];
if (!LEGACY_PLUGIN_TYPES.includes(pluginType)) {
  throw new Error(`Use 'reporter' or 'ui', got: ${pluginType}`);
}

Type guard

const isLegacyPluginType = (t) => t === 'reporter' || t === 'ui';

Try / catch

try {
  return createInvalidLegacyPluginError(msg, id, pluginType);
} catch (err) {
  if (err.message.startsWith('unknown pluginType')) {
    console.error('pluginType must be "reporter" or "ui"');
  }
  throw err;
}

Prevention

When it happens

Trigger: Programmatically calling `createInvalidLegacyPluginError(message, pluginId, pluginType)` with a pluginType other than 'reporter' or 'ui' (typo like 'reportors', capitalization, or a new plugin category not yet supported).

Common situations: Library consumers or plugin authors wiring Mocha internals directly; typos in custom tooling that wraps Mocha's error factories; future plugin types being passed to a legacy-only factory.


AI-assisted analysis of mochajs/mocha@6bcbee4fd9 (2026-09-01). Data as JSON: /api/errors/86f53e3d1a74adb2. Report an issue: GitHub.