{"record":{"id":"9aac294ee497f4c4","repo":"mochajs/mocha","slug":"err-mocha-invalid-interface","errorCode":"ERR_MOCHA_INVALID_INTERFACE","errorMessage":"invalid interface '${ui}'","messagePattern":"invalid interface '(.+?)'","errorType":"exception","errorClass":"InvalidInterfaceError","httpStatus":null,"severity":"error","filePath":"lib/mocha.cjs","lineNumber":372,"sourceCode":" * @see [CLI option](../#-ui-name-u-name)\n * @see [Interface DSLs](../#interfaces)\n * @param {string|Function} [ui=bdd] - Interface name or class.\n * @returns {Mocha} this\n * @chainable\n * @throws {Error} if requested interface cannot be loaded\n */\nMocha.prototype.ui = function (ui) {\n  var bindInterface;\n  if (typeof ui === \"function\") {\n    bindInterface = ui;\n  } else {\n    ui = ui || \"bdd\";\n    bindInterface = exports.interfaces[ui];\n    if (!bindInterface) {\n      try {\n        bindInterface = require(ui);\n      } catch {\n        throw createInvalidInterfaceError(`invalid interface '${ui}'`, ui);\n      }\n    }\n  }\n  if (bindInterface.default) {\n    bindInterface = bindInterface.default;\n  }\n\n  bindInterface(this.suite);\n\n  this.suite.on(EVENT_FILE_PRE_REQUIRE, function (context) {\n    currentContext = context;\n  });\n\n  return this;\n};\n\n/**\n * Loads `files` prior to execution. Does not support ES Modules.","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/mochajs/mocha/blob/6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a/lib/mocha.cjs#L354-L390","documentation":"Mocha.ui() selects a built-in interface (bdd, tdd, qunit, exports) from exports.interfaces; if the name is unknown it attempts require(ui) to load a third-party interface module. If that require also fails, createInvalidInterfaceError throws with \"invalid interface '<ui>'\".","triggerScenarios":"`new Mocha({ui: 'typo'})`, `mocha --ui nonexistent`, or a mocharc config with an ui value that is neither built-in nor an installable module.","commonSituations":"Misspelled ui names (e.g., 'tdd' vs 'tds'); assuming custom UIs are built in; config merging renaming the ui value; third-party interface package not installed.","solutions":["Use a built-in interface name: bdd (default), tdd, qunit, or exports","Check spelling in .mocharc or the --ui flag","Install the third-party interface package if you intend to use one, ensuring require(ui) resolves","Remove the ui override to fall back to the default bdd interface"],"exampleFix":"// before\nconst mocha = new Mocha({ ui: 'bdd2' });\n// after\nconst mocha = new Mocha({ ui: 'bdd' });","handlingStrategy":"validation","validationCode":"const BUILTIN_UIS = ['bdd', 'tdd', 'qunit', 'exports'];\nif (ui && !BUILTIN_UIS.includes(ui)) {\n  try { require.resolve(ui); } catch {\n    throw new Error(`Unknown ui '${ui}'`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  new Mocha({ ui });\n} catch (err) {\n  if (err.code === 'ERR_MOCHA_INVALID_INTERFACE') {\n    console.error(`Invalid ui '${ui}'; use bdd, tdd, qunit, exports or install the interface package`);\n  } else throw err;\n}","preventionTips":["Stick to built-in ui names unless a third-party interface is deliberately installed","Validate mocharc values (ui, reporter) against known-good lists","Install any custom interface package and confirm require(ui) resolves","Default to 'bdd' by omitting ui when unsure"],"tags":["ui","interface","config"],"backgroundTag":"invalid-interface","analyzedSha":"6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a","analyzedAt":"2026-09-01T03:41:47.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}