{"record":{"id":"34c2a70c650f9f77","repo":"jestjs/jest","slug":"jest-failed-to-parse-the-typescript-config-file","errorCode":null,"errorMessage":"Jest: Failed to parse the TypeScript config file ${configPath}\n  ${error}","messagePattern":"Jest: Failed to parse the TypeScript config file (.+?)\n  (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-config/src/readConfigFileAndSetRootDir.ts","lineNumber":97,"sourceCode":"              '  both with the native node TypeScript support and configured TypeScript loaders.\\n' +\n              '    Errors were:\\n' +\n              `    - ${requireOrImportModuleError}\\n` +\n              `    - ${loadTSConfigFileError}`\n            );\n          }\n        }\n      } else {\n        configObject = await loadTSConfigFile(configPath);\n      }\n    } else if (isJSON) {\n      const fileContent = fs.readFileSync(configPath, 'utf8');\n      configObject = parseJson(stripJsonComments(fileContent), configPath);\n    } else {\n      configObject = await requireOrImportModule<any>(configPath);\n    }\n  } catch (error) {\n    if (isTS) {\n      throw new Error(\n        `Jest: Failed to parse the TypeScript config file ${configPath}\\n` +\n          `  ${error}`,\n        {cause: error},\n      );\n    }\n\n    throw error;\n  }\n\n  if (configPath.endsWith(PACKAGE_JSON)) {\n    // Event if there's no \"jest\" property in package.json we will still use\n    // an empty object.\n    configObject = configObject.jest || {};\n  }\n\n  if (typeof configObject === 'function') {\n    configObject = await configObject();\n  }","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-config/src/readConfigFileAndSetRootDir.ts#L79-L115","documentation":"A wrapper error thrown in the outer catch of readConfigFileAndSetRootDir when the config file is TypeScript (.ts/.mts/.cts) and loading failed for any reason. The original error is attached as {cause} and its message is inlined, so the message may itself contain nested error text (including the combined 'both with native and configured loaders' preamble from the inner throw).","triggerScenarios":"Any uncaught error while loading a .ts/.mts/.cts config: syntax errors, invalid TypeScript, failed imports inside the config, missing native TS support combined with missing ts-node, or runtime exceptions thrown by the config function.","commonSituations":"Type errors in jest.config.ts that the IDE didn't flag; config importing a module that isn't installed; referencing <rootDir> in TS before normalization; or a combination of old Node + missing ts-node.","solutions":["Read the inlined inner error and {cause} to identify the real failure (syntax, missing module, version)","If native TS failed, ensure Node 22.18+/23.6+ or add a @jest-config-loader pragma with an installed loader","Run npx tsc --noEmit jest.config.ts to surface type errors independently","Temporarily move logic to a jest.config.js to isolate whether the failure is TS-specific"],"exampleFix":"// before: jest.config.ts references uninstalled preset\nexport default { preset: 'nonexistent-preset' };\n\n// after\nexport default { preset: 'ts-jest' };  // ensure it is installed","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const config = await readConfigFileAndSetRootDir(configPath);\n} catch (err) {\n  // err.cause holds the underlying load error\n  console.error('Config load failed:', err instanceof Error ? err.message : err);\n  if (err instanceof Error && err.cause instanceof Error) {\n    console.error('Underlying cause:', err.cause.message);\n  }\n  throw err;\n}","preventionTips":["Type-check jest.config.ts independently with tsc --noEmit before running Jest","Keep config files small and side-effect-free to reduce parse-time failures","Ensure all imports inside the config resolve (run the file directly with node/tsc)"],"tags":["typescript","config","loader","diagnostic-wrapper"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}