{"record":{"id":"ffb611bd398c8314","repo":"mochajs/mocha","slug":"err-mocha-invalid-reporter-reporter-or-err-mocha","errorCode":"ERR_MOCHA_INVALID_REPORTER (reporter) or ERR_MOCHA_INVALID_INTERFACE (ui)","errorMessage":"\"--${pluginType}\" can only be specified once","messagePattern":"\"--(.+?)\" can only be specified once","errorType":"error_code","errorClass":"TypeError (reporter) / Error (ui)","httpStatus":null,"severity":"error","filePath":"lib/cli/run-helpers.cjs","lineNumber":270,"sourceCode":" * it actually exists. This must be run _after_ requires are processed (see\n * {@link handleRequires}), as it'll prevent interfaces from loading otherwise.\n * @param {Object} opts - Options object\n * @param {\"reporter\"|\"ui\"} pluginType - Type of plugin.\n * @param {Object} [map] - Used as a cache of sorts;\n * `Mocha.reporters` where each key corresponds to a reporter name,\n * `Mocha.interfaces` where each key corresponds to an interface name.\n * @private\n */\nexports.validateLegacyPlugin = (opts, pluginType, map = {}) => {\n  /**\n   * This should be a unique identifier; either a string (present in `map`),\n   * or a resolvable (via `require.resolve`) module ID/path.\n   * @type {string}\n   */\n  const pluginId = opts[pluginType];\n\n  if (Array.isArray(pluginId)) {\n    throw createInvalidLegacyPluginError(\n      `\"--${pluginType}\" can only be specified once`,\n      pluginType,\n    );\n  }\n\n  const createUnknownError = (err) =>\n    createInvalidLegacyPluginError(\n      format('Could not load %s \"%s\":\\n\\n %O', pluginType, pluginId, err),\n      pluginType,\n      pluginId,\n    );\n\n  // if this exists, then it's already loaded, so nothing more to do.\n  if (!map[pluginId]) {\n    let foundId;\n    try {\n      foundId = require.resolve(pluginId);\n      map[pluginId] = require(foundId);","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/mochajs/mocha/blob/6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a/lib/cli/run-helpers.cjs#L252-L288","documentation":"The --reporter and --ui flags are 'legacy plugins' and may only be given a single value. If the parsed option value is an array (the flag was specified multiple times), Mocha throws ERR_MOCHA_INVALID_REPORTER for --reporter or ERR_MOCHA_INVALID_INTERFACE for --ui. Repeat flags are ambiguous, so Mocha refuses to guess which one to use.","triggerScenarios":"Running `mocha --reporter spec --reporter dot` or `mocha --ui bdd --ui tdd`; programmatically passing an array as opts.reporter or opts.ui into validatePlugin/run; a merged config (CLI + mocharc) where both sources set the same flag and the merge produced an array.","commonSituations":"Shell scripts or npm scripts appending extra --reporter flags; combining a mocharc `reporter` array with CLI flags; typos where a list (e.g. comma-separated intent) was passed as repeated flags.","solutions":["Specify --reporter / --ui exactly once on the command line.","If you merged configs, ensure `reporter`/`ui` are single strings, not arrays.","Check npm scripts/CI wrappers for a second injected --reporter flag (e.g. coverage tools adding one) and deduplicate.","For programmatic use, pass a string for reporter/ui in the Mocha constructor options."],"exampleFix":"// before\nmocha --reporter spec --reporter dot\n// after\nmocha --reporter dot","handlingStrategy":"validation","validationCode":"function assertSingleFlag(flagName, values) {\n  if (Array.isArray(values) || values.length > 1) {\n    throw new Error(`--${flagName} can only be specified once`);\n  }\n}\nassertSingleFlag('reporter', process.argv.filter(a => a === '--reporter'));","typeGuard":"function isSinglePluginId(v) {\n  return typeof v === 'string'; // arrays mean the flag was duplicated/merged\n}","tryCatchPattern":"try {\n  await runMochaCLI(argv);\n} catch (err) {\n  if (err.code === 'ERR_MOCHA_INVALID_REPORTER' || err.code === 'ERR_MOCHA_INVALID_INTERFACE') {\n    console.error('Deduplicate --reporter/--ui flags in your script/config');\n  }\n}","preventionTips":["Pass --reporter/--ui at most once per invocation","Check npm/CI scripts for wrappers injecting a second reporter flag","Keep mocharc reporter/ui values as single strings, not arrays","Deduplicate merged option objects before programmatic runs"],"tags":["cli","reporter","ui","duplicate-option"],"backgroundTag":"duplicate-cli-option","analyzedSha":"6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a","analyzedAt":"2026-09-01T03:41:47.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}