vitest-dev/vitest · error · Error

No codec found for type

Error message

No codec found for type ${type}

What it means

Thrown by `getCodec` in the screenshot-matcher codec registry when the requested image type string is not `'png'` (the only built-in codec). The codec encodes/decodes captured screenshot buffers for comparison and reference storage; an unknown type means the matcher cannot process the image, so it aborts. The function is called during option resolution before any capture happens.

Solutions

  1. Use `'png'` (the default and only built-in codec).
  2. If you need another format, register a custom codec and pass its name (requires extending the codec registry).
  3. Drop the explicit `type` option so the default PNG codec is used.

Example fix

// before
expect(page).toMatchScreenshot({ /* ... */, screenshotOptions: { type: 'jpeg' } })

// after
expect(page).toMatchScreenshot({ /* ... */, screenshotOptions: { type: 'png' } })
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED_CODECS = ['png'] as const
function isSupportedCodec(t: string): t is typeof SUPPORTED_CODECS[number] {
  return (SUPPORTED_CODECS as readonly string[]).includes(t)
}
if (!isSupportedCodec(type)) throw new Error(`Unsupported screenshot type: ${type}`)

Type guard

function isSupportedCodec(t: string): t is 'png' {
  return t === 'png'
}

Prevention

When it happens

Trigger: Configuring `toMatchScreenshot` options (or a custom screenshot path) with a type other than `'png'`, e.g. `'jpeg'`, `'jpg'`, `'webp'`. Calling `getCodec('jpeg')` directly.

Common situations: Passing `screenshotOptions.type: 'jpeg'` to reduce file size; a custom comparator pipeline assuming a format Vitest does not ship; misreading docs that list only PNG as supported.

Related errors


AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11). Data as JSON: /api/errors/ea8f65f8542e36fc. Report an issue: GitHub.

Appendix: source

Thrown at packages/browser/src/node/commands/screenshotMatcher/codecs/index.ts:11

import png from './png'

export function getCodec(type: 'png'): typeof png

export function getCodec(type: string) {
  switch (type) {
    case 'png':
      return png

    default:
      throw new Error(`No codec found for type ${type}`)
  }
}

export type AnyCodec = typeof png

View on GitHub (pinned to 1fa9837ec2)