GoogleChrome/lighthouse · error · Error
Invalid output mode: ${outputMode}
Error message
Invalid output mode: ${outputMode} What it means
Thrown by ReportGenerator.generateReport when an output mode string is not one of the three supported values: 'html', 'csv', or 'json'. The mode is matched by strict equality, so it is case-sensitive and typo-sensitive. The offending value is concatenated into the message for diagnostics.
Source
Thrown at report/generator/report-generator.js:187
if (outputMode === 'html') {
if (ReportGenerator.isFlowResult(result)) {
return ReportGenerator.generateFlowReportHtml(result);
}
return ReportGenerator.generateReportHtml(result);
}
// CSV report.
if (outputMode === 'csv') {
if (ReportGenerator.isFlowResult(result)) {
throw new Error('CSV output is not support for user flows');
}
return ReportGenerator.generateReportCSV(result);
}
// JSON report.
if (outputMode === 'json') {
return JSON.stringify(result, null, 2);
}
throw new Error('Invalid output mode: ' + outputMode);
});
return outputAsArray ? output : output[0];
}
}
export {ReportGenerator};
View on GitHub (pinned to 9515cd4e58)
Solutions
- Use exactly one of the lowercase literals: 'html', 'csv', or 'json'.
- Validate/whitelist the mode against ['html','csv','json'] before calling generateReport and fall back to a default like 'html'.
- Normalize input with mode.toLowerCase().trim() if the value originates from user input.
Example fix
// before ReportGenerator.generateReport(result, mode); // mode could be 'HTML' // after const VALID = ['html', 'csv', 'json']; const mode = VALID.includes(String(rawMode).toLowerCase()) ? rawMode.toLowerCase() : 'html'; ReportGenerator.generateReport(result, mode);
Defensive patterns
Strategy: validation
Validate before calling
const VALID_MODES = ['html', 'csv', 'json'];
function normalizeMode(raw) {
const m = String(raw).toLowerCase().trim();
return VALID_MODES.includes(m) ? m : 'html';
}
ReportGenerator.generateReport(result, normalizeMode(userMode)); Type guard
/** @param {unknown} m */
function isValidMode(m) {
return typeof m === 'string' && ['html', 'csv', 'json'].includes(m);
} Try / catch
try {
ReportGenerator.generateReport(result, mode);
} catch (err) {
if (err.message.startsWith('Invalid output mode:')) {
ReportGenerator.generateReport(result, 'html'); // safe default
} else throw err;
} Prevention
- Whitelist output modes against ['html','csv','json'] before calling generateReport.
- Normalize user/config-supplied modes with toLowerCase().trim().
- Default to 'html' when the supplied mode is unrecognized rather than letting it reach the throw.
When it happens
Trigger: Calling ReportGenerator.generateReport(result, outputMode) with outputMode equal to e.g. 'xml', 'HTML', 'md', or an empty/undefined value. Also triggered when passing a non-string scalar that is then compared.
Common situations: Typos or casing mistakes ('HTML' instead of 'html'); passing a value read from an unvalidated CLI flag, env var, or config file; defaulting a missing mode to undefined. Using a newer/imagined format name not implemented by this generator.
Related errors
- CSV output is not support for user flows
- Please provide a url
- Invalid value: Argument must be a string or a boolean
- Invalid values. Argument 'output' must be an array from choi
- "${str}" is not a valid 'output' value. Argument 'output' mu
AI-assisted analysis of GoogleChrome/lighthouse@9515cd4e58 (2026-08-13).
Data as JSON: /api/errors/51d40aef74ea0301.
Report an issue: GitHub.