mochajs/mocha · error · Error

invalid or unsupported TAP version: ${JSON.stringify(tapVers

Error message

invalid or unsupported TAP version: ${JSON.stringify(tapVersion)}

What it means

The TAP reporter supports only TAP versions 12 and 13. `createProducer` looks up a producer in a map keyed by the numeric `tapVersion` option and throws when the value is anything else, guarding against emitting non-conformant TAP output.

Source

Thrown at lib/reporters/tap.js:118

}

/**
 * Returns a `tapVersion`-appropriate TAP producer instance, if possible.
 *
 * @private
 * @param {string} tapVersion - Version of TAP specification to produce.
 * @returns {TAPProducer} specification-appropriate instance
 * @throws {Error} if specification version has no associated producer.
 */
function createProducer(tapVersion) {
  var producers = {
    12: new TAP12Producer(),
    13: new TAP13Producer(),
  };
  var producer = producers[tapVersion];

  if (!producer) {
    throw new Error(
      "invalid or unsupported TAP version: " + JSON.stringify(tapVersion),
    );
  }

  return producer;
}

/**
 * @summary
 * Constructs a new TAPProducer.
 *
 * @description
 * <em>Only</em> to be used as an abstract base class.
 *
 * @private
 * @constructor
 */
class TAPProducer {

View on GitHub (pinned to 6bcbee4fd9)

Solutions

  1. Set `tapVersion` to the number 13 (recommended) or 12: `{ tapVersion: 13 }`.
  2. Ensure the value is a number, not a string — quote-less `13` in JSON/JS config.
  3. Remove the `tapVersion` option entirely to use the default producer.
  4. Check the Mocha version: TAP13 support exists in Mocha >= 6.

Example fix

// before (e.g. .mocharc.json)
{ "tapVersion": "13" }

// after
{ "tapVersion": 13 }
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED_TAP_VERSIONS = [12, 13];
if (tapVersion !== undefined && !SUPPORTED_TAP_VERSIONS.includes(Number(tapVersion))) {
  throw new Error(`tapVersion must be 12 or 13, got: ${JSON.stringify(tapVersion)}`);
}

Type guard

const isSupportedTapVersion = (v) => v === 12 || v === 13;

Try / catch

try {
  const reporter = new TapReporter(runner, { tapVersion });
} catch (err) {
  if (err.message.startsWith('invalid or unsupported TAP version')) {
    console.error('Use tapVersion: 13 (or 12); omit it for defaults.');
  }
  throw err;
}

Prevention

When it happens

Trigger: `new TapReporter(runner, {tapVersion: 11})`; `{tapVersion: '13'}` (string instead of number); `{tapVersion: 99}`; the option parsed from config as a string and therefore not matching numeric keys 12/13.

Common situations: Config files specifying `"tapVersion": "13"` (string) instead of `13` (number); copying an old `tapVersion: 0`/`11` snippet from pre-Mocha-6 docs; typos like `tapVersiom`.

Related errors


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