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
- Use the supported 'png' type for screenshots/baselines.
- Convert existing baselines to PNG before pointing the matcher at them.
- 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
- Use PNG for screenshots and baselines.
- Convert existing baselines to PNG before pointing the matcher at them.
- Register a custom codec if you genuinely need another format.
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
- Unrecognized comparator ${comparator}
- Cannot take a screenshot without a test path
- Cannot take a screenshot outside of a test.
- Cannot take a screenshot in a concurrent test because concur
- 'toMatchScreenshot' cannot be used with "not"
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/ea8f65f8542e36fc.json.
Report an issue: GitHub.