{"record":{"id":"22f99a10c86a7997","repo":"GoogleChrome/lighthouse","slug":"invalid-values-argument-output-must-be-an-array","errorCode":null,"errorMessage":"Invalid values. Argument 'output' must be an array from choices \"json\", \"html\", \"csv\"","messagePattern":"Invalid values\\. Argument 'output' must be an array from choices \"json\", \"html\", \"csv\"","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/cli-flags.js","lineNumber":393,"sourceCode":"function coerceOptionalStringBoolean(value) {\n  if (value === undefined) return;\n\n  if (typeof value !== 'string' && typeof value !== 'boolean') {\n    throw new Error('Invalid value: Argument must be a string or a boolean');\n  }\n  return value;\n}\n\n/**\n * Coerce output CLI input to `LH.SharedFlagsSettings['output']` or throw if not possible.\n * @param {Array<unknown>} values\n * @return {Array<LH.OutputMode>}\n */\nfunction coerceOutput(values) {\n  const outputTypes = ['json', 'html', 'csv'];\n  const errorHint = `Argument 'output' must be an array from choices \"${outputTypes.join('\", \"')}\"`;\n  if (!values.every(item => typeof item === 'string')) {\n    throw new Error('Invalid values. ' + errorHint);\n  }\n  // Allow parsing of comma-separated values.\n  const strings = values.flatMap(value => value.split(','));\n  const validValues = strings.filter(/** @return {str is LH.OutputMode} */ str => {\n    if (!outputTypes.includes(str)) {\n      throw new Error(`\"${str}\" is not a valid 'output' value. ` + errorHint);\n    }\n    return true;\n  });\n\n  return validValues;\n}\n\n/**\n * Verifies outputPath is something we can actually write to.\n * @param {unknown=} value\n * @return {string=}\n */","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/GoogleChrome/lighthouse/blob/9515cd4e58ebed69f78742d932b501c2cab8ad8f/cli/cli-flags.js#L375-L411","documentation":"The --output flag accepts an array of output formats. Lighthouse's coerceOutput function first checks that every element in the values array is a string before attempting to split on commas and validate against the allowed set. This specific error fires at the type-check stage — a non-string element (number, object, array) is present before format validation even begins.","triggerScenarios":"Passing --output with a value that yargs delivers as a non-string array element. For example, a value that parses as a number or object before reaching the string-type guard. This is distinct from error 4, which fires when a string value is not in the allowed set.","commonSituations":"Programmatic yargs configuration passing a mixed-type array to --output; shell expansion injecting a non-string token; edge cases in yargs array coercion with unusual flag syntax.","solutions":["Ensure all --output values are quoted strings from the set json, html, csv: lighthouse --output=json --output=html","Use comma-separated string form: lighthouse --output=json,html","Remove any non-string values from the --output argument"],"exampleFix":"# before (programmatic or malformed shell)\nlighthouse --output=123\n# after\nlighthouse --output=json","handlingStrategy":"validation","validationCode":"// Validate output values before passing to Lighthouse\nconst VALID_OUTPUTS = ['json', 'html', 'csv'];\nfunction validateOutputValues(values) {\n  if (!values.every(v => typeof v === 'string')) {\n    throw new Error('All --output values must be strings');\n  }\n}","typeGuard":"/** @param {unknown} v */\nfunction isStringArray(v) {\n  return Array.isArray(v) && v.every(item => typeof item === 'string');\n}","tryCatchPattern":null,"preventionTips":["Always quote --output values to ensure string type","Use comma-separated string form: --output=json,html","Avoid programmatic flag construction that could inject non-string values"],"tags":["cli","validation","output"],"backgroundTag":null,"analyzedSha":"9515cd4e58ebed69f78742d932b501c2cab8ad8f","analyzedAt":"2026-08-13T06:28:10.346Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}