GoogleChrome/lighthouse · error · Error

Invalid values. Argument 'output' must be an array from choi

Error message

Invalid values. Argument 'output' must be an array from choices "json", "html", "csv"

What it means

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.

Source

Thrown at cli/cli-flags.js:393

function coerceOptionalStringBoolean(value) {
  if (value === undefined) return;

  if (typeof value !== 'string' && typeof value !== 'boolean') {
    throw new Error('Invalid value: Argument must be a string or a boolean');
  }
  return value;
}

/**
 * Coerce output CLI input to `LH.SharedFlagsSettings['output']` or throw if not possible.
 * @param {Array<unknown>} values
 * @return {Array<LH.OutputMode>}
 */
function coerceOutput(values) {
  const outputTypes = ['json', 'html', 'csv'];
  const errorHint = `Argument 'output' must be an array from choices "${outputTypes.join('", "')}"`;
  if (!values.every(item => typeof item === 'string')) {
    throw new Error('Invalid values. ' + errorHint);
  }
  // Allow parsing of comma-separated values.
  const strings = values.flatMap(value => value.split(','));
  const validValues = strings.filter(/** @return {str is LH.OutputMode} */ str => {
    if (!outputTypes.includes(str)) {
      throw new Error(`"${str}" is not a valid 'output' value. ` + errorHint);
    }
    return true;
  });

  return validValues;
}

/**
 * Verifies outputPath is something we can actually write to.
 * @param {unknown=} value
 * @return {string=}
 */

View on GitHub (pinned to 9515cd4e58)

Solutions

  1. Ensure all --output values are quoted strings from the set json, html, csv: lighthouse --output=json --output=html
  2. Use comma-separated string form: lighthouse --output=json,html
  3. Remove any non-string values from the --output argument

Example fix

# before (programmatic or malformed shell)
lighthouse --output=123
# after
lighthouse --output=json
Defensive patterns

Strategy: validation

Validate before calling

// Validate output values before passing to Lighthouse
const VALID_OUTPUTS = ['json', 'html', 'csv'];
function validateOutputValues(values) {
  if (!values.every(v => typeof v === 'string')) {
    throw new Error('All --output values must be strings');
  }
}

Type guard

/** @param {unknown} v */
function isStringArray(v) {
  return Array.isArray(v) && v.every(item => typeof item === 'string');
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of GoogleChrome/lighthouse@9515cd4e58 (2026-08-13). Data as JSON: /api/errors/22f99a10c86a7997. Report an issue: GitHub.