vitest-dev/vitest · error · Error
pretty-format: Option "theme" has a key
Error message
pretty-format: Option "theme" has a key "${key}" whose value "${value}" is undefined in ansi-styles. What it means
When highlight is enabled, getColorsHighlight maps each DEFAULT_THEME key to an ansi-styles color. If the configured theme value (e.g. a custom color name) does not exist in ansi-styles (no matching export with open/close strings), the build throws, naming the offending key and value.
Example fix
// before
format(value, { highlight: true, theme: { tag: 'purple' } })
// after
format(value, { highlight: true, theme: { tag: 'magenta' } }) Defensive patterns
Strategy: validation
Validate before calling
import * as ansiStyles from 'ansi-styles'
for (const [key, value] of Object.entries(theme)) {
if (!ansiStyles[value] || typeof ansiStyles[value].open !== 'string') {
throw new Error(`invalid theme color '${value}' for key '${key}'`)
}
}
format(value, { highlight: true, theme }) Type guard
function isValidThemeColor(name: string): boolean { const c = (ansiStyles as any)[name]; return !!c && typeof c.open === 'string' && typeof c.close === 'string' } Prevention
- Restrict theme values to documented ansi-styles exports
- Validate theme at config load time
- Avoid inventing color names not in ansi-styles
When it happens
Trigger: Passing a custom theme option with a color name not supported by ansi-styles, e.g. theme: { tag: 'purple' } where 'purple' is not an ansi-styles export; or a typo like 'reg' instead of 'red'.
Common situations: Customizing the highlight theme with an invalid color name; copy-pasting a color name from a different palette; ansi-styles version where the named export was removed/renamed.
Related errors
- Asymmetric matcher does not implement toAsymmetricMatcher()
- error.message
- pretty-format: Options "min" and "indent" cannot be used…
- pretty-format: Plugin must return type "string" but instead…
- pretty-format: Unknown option
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/587ee99236e0acc8.
Report an issue: GitHub.
Appendix: source
Thrown at packages/pretty-format/src/index.ts:494
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'
) {
colors[key] = color
}
else {
throw new Error(
`pretty-format: Option "theme" has a key "${key}" whose value "${value}" is undefined in ansi-styles.`,
)
}
return colors
}, Object.create(null))
}
function getColorsEmpty(): Colors {
return DEFAULT_THEME_KEYS.reduce((colors, key) => {
colors[key] = { close: '', open: '' }
return colors
}, Object.create(null))
}
function getPrintFunctionName(options?: OptionsReceived) {
return options?.printFunctionName ?? DEFAULT_OPTIONS.printFunctionName
}
View on GitHub (pinned to 1fa9837ec2)