vitest-dev/vitest · error · Error

No codec found for type ${type}

Error message

No codec found for type ${type}

What it means

Thrown by `getCodec` at codecs/index.ts:10-11 when the requested image type is not 'png' — the only built-in codec. The screenshot matcher decodes reference images and encodes diffs using a codec keyed by image type; an unsupported type means decoding/encoding cannot proceed.

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 d568f8ce37)

Solutions

  1. Use the supported 'png' type for screenshots/baselines.
  2. Convert existing baselines to PNG before pointing the matcher at them.
  3. If you need another format, contribute/register a codec in the registry (extend the `Codec` interface).

Example fix

// before
expect(page).toMatchScreenshot({ /* options.imageType: 'jpeg' */ })

// after
expect(page).toMatchScreenshot({ /* use default PNG */ })
Defensive patterns

Strategy: validation

Validate before calling

function isSupportedImageType(t: string): t is 'png' {
  return t === 'png'
}
if (!isSupportedImageType(imageType)) throw new Error('only png is supported')

Type guard

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

Prevention

When it happens

Trigger: Configuring `toMatchScreenshot` options to use an image type other than 'png' (e.g. 'jpeg', 'webp'). A reference baseline file in a format other than PNG. A custom codec that wasn't registered.

Common situations: Users wanting JPEG/WebP baselines without registering a codec. Tooling that produces screenshots in a default format the host browser uses. Misreading the type option as a quality/format string.

Related errors


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