{"id":"ee429e646e267454","repo":"jestjs/jest","slug":"could-not-infer-prettier-parser-for-file-filepat","errorCode":null,"errorMessage":"Could not infer Prettier parser for file ${filepath}","messagePattern":"Could not infer Prettier parser for file (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-snapshot/src/worker.ts","lineNumber":43,"sourceCode":"  ) => {\n    prettier ??= require(\n      /*webpackIgnore: true*/\n      require.resolve(prettierPath, {\n        [Symbol.for('jest-resolve-outside-vm-option')]: true,\n      }),\n    );\n\n    const config = await prettier.resolveConfig(filepath, {\n      editorconfig: true,\n    });\n\n    const inferredParser: string | null =\n      typeof config?.parser === 'string'\n        ? config.parser\n        : await getInferredParser(filepath);\n\n    if (!inferredParser) {\n      throw new Error(`Could not infer Prettier parser for file ${filepath}`);\n    }\n\n    sourceFileWithSnapshots = await prettier.format(sourceFileWithSnapshots, {\n      ...config,\n      filepath,\n      parser: inferredParser,\n    });\n\n    const {ast, text: parsedSourceFileWithSnapshots} =\n      // @ts-expect-error private API\n      await prettier.__debug.parse(sourceFileWithSnapshots, {\n        ...config,\n        filepath,\n        originalText: sourceFileWithSnapshots,\n        parser: inferredParser,\n      });\n    processPrettierAst(ast, config, snapshotMatcherNames, true);\n    // Snapshots have now been inserted. Run prettier to make sure that the code is","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-snapshot/src/worker.ts#L25-L61","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before: jest.config.js with default prettier sniffing on an odd extension\n// (test file: foo.test.mjsarb)\n// after: tell prettier how to parse via .prettierrc\n{ \"overrides\": [{ \"files\": \"*.mjsarb\", \"options\": { \"parser\": \"babel\" } }] }","handlingStrategy":"validation","validationCode":"const prettier = require('prettier');\nconst info = await prettier.getFileInfo(filepath);\nif (!info.inferredParser && !prettierConfig.parser)\n  throw new Error(`configure a prettier parser for ${filepath} or rename it`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["jest-snapshot","prettier","inline-snapshot","config"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}