{"record":{"id":"958c86c434108884","repo":"mochajs/mocha","slug":"err-mocha-unsupported-958c86","errorCode":"ERR_MOCHA_UNSUPPORTED","errorMessage":"file output not supported in browser","messagePattern":"file output not supported in browser","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/reporters/xunit.js","lineNumber":66,"sourceCode":"   * @param {Object} [options] - runner options\n   */\n  constructor(runner, options) {\n    super(runner, options);\n\n    var stats = this.stats;\n    var tests = [];\n    var self = this;\n\n    // the name of the test suite, as it will appear in the resulting XML file\n    var suiteName;\n\n    // the default name of the test suite if none is provided\n    var DEFAULT_SUITE_NAME = \"Mocha Tests\";\n\n    if (options && options.reporterOptions) {\n      if (options.reporterOptions.output) {\n        if (!fs.createWriteStream) {\n          throw createUnsupportedError(\"file output not supported in browser\");\n        }\n\n        fs.mkdirSync(path.dirname(options.reporterOptions.output), {\n          recursive: true,\n        });\n        self.fileStream = fs.createWriteStream(options.reporterOptions.output);\n      }\n\n      // get the suite name from the reporter options (if provided)\n      suiteName = options.reporterOptions.suiteName;\n    }\n\n    // fall back to the default suite name\n    suiteName = suiteName || DEFAULT_SUITE_NAME;\n\n    runner.on(EVENT_TEST_PENDING, function (test) {\n      tests.push(test);\n    });","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/mochajs/mocha/blob/6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a/lib/reporters/xunit.js#L48-L84","documentation":"The XUnit reporter writes test results to a file given by reporterOptions.output. In browser bundles fs.createWriteStream does not exist, so the reporter throws ERR_MOCHA_UNSUPPORTED to signal file output is impossible. This prevents a confusing downstream crash when trying to write the stream.","triggerScenarios":"new XUnitReporter(runner, {reporterOptions: {output: 'xunit.xml'}}) executed in a browser (fs.createWriteStream undefined), e.g. via `mocha --reporter xunit --reporter-option output=report.xml` in a browser build.","commonSituations":"Browser-based CI runners reusing Node mocharc with xunit output; test frameworks embedding Mocha in the browser but requesting XML file reports; forgetting that xunit file output is Node-only.","solutions":["Drop the output reporter option in browser environments; capture the reporter's XML string via runner events instead.","Run xunit with file output only in Node via the mocha CLI.","In browser tests, have the harness collect XUnit's output string and POST it to a server that writes the file.","Use a separate Node-only mocharc (e.g. .mocharc.node.yml) for file-output reporting."],"exampleFix":"// before\nmocha.setup({reporter: 'xunit', reporterOptions: {output: 'out.xml'}});\n// after\nmocha.setup({reporter: 'xunit'}); // capture reporter output string in browser harness","handlingStrategy":"validation","validationCode":"if (typeof window !== 'undefined' && reporterOptions && reporterOptions.output) {\n  delete reporterOptions.output; // xunit file output requires Node fs\n}","typeGuard":"function supportsXunitFileOutput() {\n  return typeof fs !== 'undefined' && typeof fs.createWriteStream === 'function';\n}","tryCatchPattern":"try {\n  new Mocha({reporter: 'xunit', reporterOptions: {output: 'out.xml'}}).run(fn);\n} catch (err) {\n  if (err.code === 'ERR_MOCHA_UNSUPPORTED') {\n    // switch to string-based xunit capture in browser\n  }\n}","preventionTips":["Only use output= with xunit under Node/CLI","Use separate configs for browser and Node test runs","In browser harnesses capture the reporter output string and send it to a server","Audit CI configs that share mocharc across environments"],"tags":["browser","reporter","xunit","unsupported-feature"],"backgroundTag":"browser-env-unsupported-api","analyzedSha":"6bcbee4fd9a95351cedf0fdcb14c7d696486bc5a","analyzedAt":"2026-09-01T03:41:47.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}