vitest-dev/vitest · error · Error

pretty-format: Unknown option "${key}".

Error message

pretty-format: Unknown option "${key}".

What it means

`format()` runs `validateOptions`, which rejects any options key not present in `DEFAULT_OPTIONS`. This catches typos and removed/renamed options early instead of silently ignoring them, and reports the offending key name.

Source

Thrown at packages/pretty-format/src/index.ts:471

  // (Node's limit is buffer.constants.MAX_STRING_LENGTH ~ 512MB)
  maxOutputLength: 1_000_000,
  maxWidth: Number.POSITIVE_INFINITY,
  min: false,
  plugins: [],
  printBasicPrototype: true,
  printFunctionName: true,
  printShadowRoot: true,
  theme: DEFAULT_THEME,
  singleQuote: false,
  quoteKeys: true,
  spacingInner: '\n',
  spacingOuter: '\n',
} satisfies Options

function validateOptions(options: OptionsReceived) {
  for (const key of Object.keys(options)) {
    if (!Object.hasOwn(DEFAULT_OPTIONS, key)) {
      throw new Error(`pretty-format: Unknown option "${key}".`)
    }
  }

  if (options.min && options.indent !== undefined && options.indent !== 0) {
    throw new Error(
      'pretty-format: Options "min" and "indent" cannot be used together.',
    )
  }
}

function getColorsHighlight(): Colors {
  return DEFAULT_THEME_KEYS.reduce((colors, key) => {
    const value = DEFAULT_THEME[key]
    const color = value && (styles as any)[value]
    if (
      color
      && typeof color.close === 'string'
      && typeof color.open === 'string'

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Cross-check the key against `DEFAULT_OPTIONS` in `packages/pretty-format/src/index.ts`.
  2. Fix the typo or remove the unknown option.
  3. If you need a behavior that no longer exists, find the replacement option in the changelog.

Example fix

// before
format(value, { hilight: true, indent: 2 })

// after
format(value, { highlight: true, indent: 2 })
Defensive patterns

Strategy: validation

Validate before calling

import { DEFAULT_OPTIONS } from '@vitest/pretty-format'

function assertOptions(opts: Record<string, unknown>) {
  for (const key of Object.keys(opts)) {
    if (!Object.prototype.hasOwnProperty.call(DEFAULT_OPTIONS, key)) {
      throw new Error(`pretty-format: Unknown option '${key}'. Valid: ${Object.keys(DEFAULT_OPTIONS).join(', ')}`)
    }
  }
}

Type guard

import type { OptionsReceived } from '@vitest/pretty-format'

function isPrettyFormatOptions(v: unknown): v is OptionsReceived {
  if (typeof v !== 'object' || v === null) return false
  return Object.keys(v).every(k => k in DEFAULT_OPTIONS)
}

Prevention

When it happens

Trigger: `format(value, { hilight: true })` (typo), or passing an option name from a different pretty-format version (e.g. jest's `printBasicPrototype` spelling drift), or a removed option after an upgrade.

Common situations: Migrating config from Jest's pretty-format; typos; copy-pasting options across versions; using an option that was renamed/removed.

Related errors


AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03). Data as JSON: /data/errors/f0d40956478f91dd.json. Report an issue: GitHub.