{"id":"587ee99236e0acc8","repo":"vitest-dev/vitest","slug":"pretty-format-option-theme-has-a-key-key-w","errorCode":null,"errorMessage":"pretty-format: Option \"theme\" has a key \"${key}\" whose value \"${value}\" is undefined in ansi-styles.","messagePattern":"pretty-format: Option \"theme\" has a key \"(.+?)\" whose value \"(.+?)\" is undefined in ansi-styles\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/pretty-format/src/index.ts","lineNumber":494,"sourceCode":"    throw new Error(\n      'pretty-format: Options \"min\" and \"indent\" cannot be used together.',\n    )\n  }\n}\n\nfunction getColorsHighlight(): Colors {\n  return DEFAULT_THEME_KEYS.reduce((colors, key) => {\n    const value = DEFAULT_THEME[key]\n    const color = value && (styles as any)[value]\n    if (\n      color\n      && typeof color.close === 'string'\n      && typeof color.open === 'string'\n    ) {\n      colors[key] = color\n    }\n    else {\n      throw new Error(\n        `pretty-format: Option \"theme\" has a key \"${key}\" whose value \"${value}\" is undefined in ansi-styles.`,\n      )\n    }\n    return colors\n  }, Object.create(null))\n}\n\nfunction getColorsEmpty(): Colors {\n  return DEFAULT_THEME_KEYS.reduce((colors, key) => {\n    colors[key] = { close: '', open: '' }\n    return colors\n  }, Object.create(null))\n}\n\nfunction getPrintFunctionName(options?: OptionsReceived) {\n  return options?.printFunctionName ?? DEFAULT_OPTIONS.printFunctionName\n}\n","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/pretty-format/src/index.ts#L476-L512","documentation":"When `highlight: true`, pretty-format resolves each theme color name (comment, content, prop, tag, value) to a style function on the `tinyrainbow` dependency. If a configured color value has no matching entry in tinyrainbow, `getColorsHighlight` throws reporting the offending key/value. In practice this is a dependency/version mismatch rather than user error, since the code resolves the default theme keys.","triggerScenarios":"`format(value, { highlight: true })` on a system where the installed `tinyrainbow` lacks one of the resolved color names (e.g. a major version removed/renamed `gray` or `reset`), or a build that patches `DEFAULT_THEME` to an unsupported value.","commonSituations":"tinyrainbow major upgrade changing the color API; dedupe/hoisting picking an incompatible tinyrainbow version in a monorepo; custom fork of pretty-format with an altered theme.","solutions":["Ensure a compatible `tinyrainbow` version is installed and hoisted (one that exports gray/reset/yellow/cyan/green).","Disable highlighting: `format(value, { highlight: false })`.","Run `pnpm why tinyrainbow` / `npm ls tinyrainbow` to find and resolve version conflicts."],"exampleFix":"// before — triggers when tinyrainbow lacks a color\nformat(value, { highlight: true })\n\n// after — bypass color resolution\nformat(value, { highlight: false })","handlingStrategy":"validation","validationCode":"import styles from 'tinyrainbow'\nimport { DEFAULT_THEME } from '@vitest/pretty-format'\n\nfunction assertThemeColorsAvailable() {\n  for (const [key, value] of Object.entries(DEFAULT_THEME)) {\n    if (value && typeof (styles as any)[value]?.open !== 'string') {\n      throw new Error(`tinyrainbow is missing color '${value}' (theme key '${key}'). Fix dependency or disable highlight.`)\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"let output: string\ntry {\n  output = format(value, { highlight: true })\n}\ncatch (err) {\n  if (err instanceof Error && /is undefined in ansi-styles/.test(err.message)) {\n    // tinyrainbow version mismatch — fall back to no color\n    output = format(value, { highlight: false })\n  } else {\n    throw err\n  }\n}","preventionTips":["Pin a compatible `tinyrainbow` version in your lockfile.","In monorepos, run `pnpm why tinyrainbow` to detect version conflicts before they bite.","Default to `highlight: false` in non-TTY/CI contexts where colors aren't needed."],"tags":["pretty-format","theme","dependency","highlight"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}