{"id":"2ef1c4315269f058","repo":"jestjs/jest","slug":"jest-transformers-have-not-been-loaded-yet-make","errorCode":null,"errorMessage":"Jest: Transformers have not been loaded yet - make sure to run `loadTransformers` and wait for it to complete before starting to transform files","messagePattern":"Jest: Transformers have not been loaded yet - make sure to run `loadTransformers` and wait for it to complete before starting to transform files","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-transform/src/ScriptTransformer.ts","lineNumber":312,"sourceCode":"            throw new TypeError(makeInvalidTransformerError(transformPath));\n          }\n          const res = {transformer, transformerConfig};\n          const transformCacheKey = this._buildTransformCacheKey(\n            this._cache.transformRegExp?.[i]?.[0].source ??\n              new RegExp(transformPattern).source,\n            transformPath,\n          );\n          this._transformCache.set(transformCacheKey, res);\n        },\n      ),\n    );\n\n    this._transformsAreLoaded = true;\n  }\n\n  private _getTransformer(filename: string) {\n    if (!this._transformsAreLoaded) {\n      throw new Error(\n        'Jest: Transformers have not been loaded yet - make sure to run `loadTransformers` and wait for it to complete before starting to transform files',\n      );\n    }\n\n    if (this._config.transform.length === 0) {\n      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    );","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-transform/src/ScriptTransformer.ts#L294-L330","documentation":"Thrown by `_getTransformer` (ScriptTransformer.ts:311-315) when `_transformsAreLoaded` is still false. `loadTransformers()` is async and must complete before any file is transformed; if `_getTransformer` runs first, no transformer cache is populated and the guard fires rather than silently skipping configured transforms.","triggerScenarios":"Calling `transformSource`/`transformSourceAsync` (or `requireAndTranspileModule`) on a `ScriptTransformer` instance that was constructed directly without awaiting `loadTransformers()`. Public factories like `createScriptTransformer` await it automatically; bypassing them or racing the load triggers this.","commonSituations":"A custom Jest runner/test environment that instantiates `ScriptTransformer` directly; a refactor that switched from `createScriptTransformer` to `new ScriptTransformer(...)` and forgot the await; an integration that constructs the transformer lazily but transforms a file before the load promise settles.","solutions":["Use the public async factory `createScriptTransformer(config)` which awaits `loadTransformers()` before returning.","If constructing `ScriptTransformer` directly, `await transformer.loadTransformers()` before any `transformSource*` call.","Audit custom runners/environments to ensure the transformer is fully loaded in their async setup phase."],"exampleFix":"// before\nconst transformer = new ScriptTransformer(config);\ntransformer.transformSourceAsync(filename, source); // throws 209\n// after\nconst transformer = await createScriptTransformer(config);\ntransformer.transformSourceAsync(filename, source);","handlingStrategy":"validation","validationCode":"// Always go through the async factory; assert the flag before transforming\nconst transformer = await createScriptTransformer(config);\nif (!transformer._transformsAreLoaded) throw new Error('loadTransformers not awaited');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use `createScriptTransformer(config)` rather than `new ScriptTransformer(...)`.","If constructing directly, `await transformer.loadTransformers()` in setup before any transform call.","In custom runners, do all transformer loading in an async `setup()` phase."],"tags":["jest-transform","lifecycle","async","api-misuse"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}