{"id":"c8ef7a741edaaee6","repo":"jestjs/jest","slug":"jest-was-unable-to-load-the-transformer-defined-fo","errorCode":null,"errorMessage":"Jest was unable to load the transformer defined for ${filename}. This is a bug in Jest, please open up an issue","messagePattern":"Jest was unable to load the transformer defined for (.+?)\\. This is a bug in Jest, please open up an issue","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-transform/src/ScriptTransformer.ts","lineNumber":336,"sourceCode":"      return null;\n    }\n\n    const transformPatternAndPath = this._getTransformPatternAndPath(filename);\n    if (!Array.isArray(transformPatternAndPath)) {\n      return null;\n    }\n\n    const [transformPattern, transformPath] = transformPatternAndPath;\n    const transformCacheKey = this._buildTransformCacheKey(\n      transformPattern,\n      transformPath,\n    );\n    const transformer = this._transformCache.get(transformCacheKey);\n    if (transformer !== undefined) {\n      return transformer;\n    }\n\n    throw new Error(\n      `Jest was unable to load the transformer defined for ${filename}. This is a bug in Jest, please open up an issue`,\n    );\n  }\n\n  private _instrumentFile(\n    filename: string,\n    input: TransformedSource,\n    canMapToInput: boolean,\n    options: ReducedTransformOptions,\n  ): TransformedSource {\n    const inputCode = typeof input === 'string' ? input : input.code;\n    const inputMap = typeof input === 'string' ? null : input.map;\n\n    const result = babelTransform(inputCode, {\n      auxiliaryCommentBefore: ' istanbul ignore next ',\n      babelrc: false,\n      caller: {\n        name: '@jest/transform',","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-transform/src/ScriptTransformer.ts#L318-L354","documentation":"Thrown by `_getTransformer` (ScriptTransformer.ts:336-338) when `_transformsAreLoaded` is true and a transform pattern matched the filename, but `_transformCache.get(transformCacheKey)` returns undefined. The contract is that `loadTransformers` populates the cache for every configured entry; a miss means the cache key computed at lookup differs from the key computed at load - an internal Jest consistency failure.","triggerScenarios":"Requires `_buildTransformCacheKey` (which mixes the transform-pattern regex source and the transformPath) to be non-deterministic between the load loop (ScriptTransformer.ts:297-301) and the lookup (ScriptTransformer.ts:327-330) - e.g. a regex `source` that varies, or a transformPath that resolves differently across calls.","commonSituations":"Effectively unreachable in stock Jest; seen with monkey-patches that mutate `_config.transform` after load, or with a custom fork that changes cache-key construction. The message itself directs users to file a Jest issue.","solutions":["Confirm you are on a released Jest version (not a patched fork) and file the issue requested by the message if so.","If you monkey-patch `config.transform` or `_transformCache` at runtime, stop - the cache is populated once at load time.","Ensure `_buildTransformCacheKey` inputs (regex source, resolved transform path) are stable strings across calls."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Internal consistency failure - catch, capture diagnostics, and report\ntry { transformer.transformSourceAsync(file, src); }\ncatch (e) {\n  if (/unable to load the transformer.*bug in Jest/.test(e.message)) {\n    captureState({ transform: config.transform, cache: [...transformer._transformCache.keys()] });\n    throw new Error('file a Jest issue: transformer cache miss after load', { cause: e });\n  }\n  throw e;\n}","preventionTips":["Do not mutate `config.transform` or `_transformCache` after `loadTransformers()` completes.","Use released Jest versions; if you fork, keep `_buildTransformCacheKey` inputs stable.","Cache keys must depend only on the regex source string and the resolved transform path."],"tags":["jest-transform","internal","bug","cache"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}