jestjs/jest · error · Error
Could not infer Prettier parser for file ${filepath}
Error message
Could not infer Prettier parser for file ${filepath} What it means
Thrown by the prettier worker (worker.ts:42-44) when neither the resolved prettier config's `parser` field nor `prettier.getFileInfo(filepath).inferredParser` yields a parser name. Prettier formats the inline-snapshot source after the babel patcher writes it; without a parser it cannot format and Jest aborts the snapshot write.
Source
Thrown at packages/jest-snapshot/src/worker.ts:43
) => {
prettier ??= require(
/*webpackIgnore: true*/
require.resolve(prettierPath, {
[Symbol.for('jest-resolve-outside-vm-option')]: true,
}),
);
const config = await prettier.resolveConfig(filepath, {
editorconfig: true,
});
const inferredParser: string | null =
typeof config?.parser === 'string'
? config.parser
: await getInferredParser(filepath);
if (!inferredParser) {
throw new Error(`Could not infer Prettier parser for file ${filepath}`);
}
sourceFileWithSnapshots = await prettier.format(sourceFileWithSnapshots, {
...config,
filepath,
parser: inferredParser,
});
const {ast, text: parsedSourceFileWithSnapshots} =
// @ts-expect-error private API
await prettier.__debug.parse(sourceFileWithSnapshots, {
...config,
filepath,
originalText: sourceFileWithSnapshots,
parser: inferredParser,
});
processPrettierAst(ast, config, snapshotMatcherNames, true);
// Snapshots have now been inserted. Run prettier to make sure that the code isView on GitHub (pinned to f49721c78e)
Solutions
- Ensure the test file has a mainstream extension prettier understands (`.js`, `.ts`, `.jsx`, `.tsx`, `.mjs`, `.mts`).
- Set `parser` explicitly in `.prettierrc` or in the `prettierPath`-resolved config for the affected files.
- Install the prettier plugin matching the file type (e.g. `prettier-plugin-svelte`).
- If prettier is unwanted, configure `prettierPath: null` in the Jest snapshot config to skip formatting (Jest will write unformatted inline snapshots).
Example fix
// before: jest.config.js with default prettier sniffing on an odd extension
// (test file: foo.test.mjsarb)
// after: tell prettier how to parse via .prettierrc
{ "overrides": [{ "files": "*.mjsarb", "options": { "parser": "babel" } }] } Defensive patterns
Strategy: validation
Validate before calling
const prettier = require('prettier');
const info = await prettier.getFileInfo(filepath);
if (!info.inferredParser && !prettierConfig.parser)
throw new Error(`configure a prettier parser for ${filepath} or rename it`); Prevention
- Use mainstream test-file extensions (.js/.ts/.jsx/.tsx/.mjs/.mts).
- If using an unusual extension, add a prettier `overrides` entry mapping it to a parser.
- If prettier is unwanted, set `snapshotFormat`/`prettierPath: null` to skip formatting.
When it happens
Trigger: Writing/updating an inline snapshot in a test file whose extension prettier does not recognize (e.g. `.snap`, custom extension), or where the project's prettier config sets no parser and prettier's file-info heuristic returns null.
Common situations: Test files with unusual extensions (`.test.jsx.cjs` mishaps); projects without prettier installed/configured where prettier falls back to extension sniffing that fails; `.mdx`/`.vue`/`.svelte` test files without the matching prettier plugin installed; renaming test files to extensions prettier ignores.
Related errors
- Could not infer Prettier parser for file ${sourceFilePath}
- jest-snapshot: Failed to parse ${sourceFilePath}
- Jest: no snapshot insert location found
- Jest: Multiple inline snapshots for the same call are not su
- Jest: Couldn't locate all inline snapshots.
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/ee429e646e267454.json.
Report an issue: GitHub.