jestjs/jest · error · Error
Jest: Failed to parse the TypeScript config file
Error message
Jest: Failed to parse the TypeScript config file ${configPath}
${error} What it means
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).
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
Example fix
// before: jest.config.ts references uninstalled preset
export default { preset: 'nonexistent-preset' };
// after
export default { preset: 'ts-jest' }; // ensure it is installed Defensive patterns
Strategy: try-catch
Try / catch
try {
const config = await readConfigFileAndSetRootDir(configPath);
} catch (err) {
// err.cause holds the underlying load error
console.error('Config load failed:', err instanceof Error ? err.message : err);
if (err instanceof Error && err.cause instanceof Error) {
console.error('Underlying cause:', err.cause.message);
}
throw err;
} Prevention
- 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)
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- jest.config.mts requires native TypeScript support. Ensure…
- Jest: ' ' is not a valid TypeScript configuration loader.
- Jest: ' ' is required for the TypeScript configuration…
- Jest: You can only define a single loader through…
- Can't find a root directory while resolving a config file…
AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10).
Data as JSON: /api/errors/34c2a70c650f9f77.
Report an issue: GitHub.
Appendix: source
Thrown at packages/jest-config/src/readConfigFileAndSetRootDir.ts:97
' both with the native node TypeScript support and configured TypeScript loaders.\n' +
' Errors were:\n' +
` - ${requireOrImportModuleError}\n` +
` - ${loadTSConfigFileError}`
);
}
}
} else {
configObject = await loadTSConfigFile(configPath);
}
} else if (isJSON) {
const fileContent = fs.readFileSync(configPath, 'utf8');
configObject = parseJson(stripJsonComments(fileContent), configPath);
} else {
configObject = await requireOrImportModule<any>(configPath);
}
} catch (error) {
if (isTS) {
throw new Error(
`Jest: Failed to parse the TypeScript config file ${configPath}\n` +
` ${error}`,
{cause: error},
);
}
throw error;
}
if (configPath.endsWith(PACKAGE_JSON)) {
// Event if there's no "jest" property in package.json we will still use
// an empty object.
configObject = configObject.jest || {};
}
if (typeof configObject === 'function') {
configObject = await configObject();
}View on GitHub (pinned to 8e6d128e4a)