Jest will not load jest.config.ts
Failed to parse the TypeScript config fileShort answer
Jest loads jest.config.ts through ts-node unless you choose another loader. If ts-node is missing or cannot compile the file, Jest fails to parse it. Install ts-node, switch the loader to esbuild-register with a docblock, or rename the file to jest.config.js.
Fix it fast
1Find out which cause you have
Read the full message under the headline. It usually names the real error from the loader.
npx jest --showConfig npm ls ts-node esbuild-register2Match what you see, then jump to its fix
- 1
npm ls shows no ts-node, or the message mentions ts-nodets-node is not installedFix - 2
The wrapped error is a TypeScript or module error raised while loading the configts-node cannot compile the file in your project setupFix - 3
A loader chain is the only thing standing between you and a green runYou do not need a TypeScript config at allFix
- 1
What does the error look like?
Failed to parse the TypeScript config fileJest: Failed to parse the TypeScript config file
Cause 1 of 3
ts-node is not installed
1Check
By default Jest needs ts-node to read a TypeScript config file.
npm ls ts-node2Fix
Add ts-node as a dev dependency.
npm install --save-dev ts-node3Verify
Run Jest.
npx jest --showConfigConfirmed by jestjs.io
Cause 2 of 3
ts-node cannot compile the file in your project setup
1Check
Jest supports a second loader. Name it in a docblock at the very top of the config file.
head -n 5 jest.config.ts2Fix
Install esbuild-register and select it in the docblock.
/** @jest-config-loader esbuild-register */
import type { Config } from 'jest';
const config: Config = {
verbose: true,
};
export default config;3Verify
Print the resolved config.
npm install --save-dev esbuild-register
npx jest --showConfigConfirmed by jestjs.io
Cause 3 of 3
You do not need a TypeScript config at all
1Check
Jest discovers config files named jest.config with js, ts, mjs, mts, cjs, cts or json extensions.
ls jest.config.*2Fix
Rename the file to a JavaScript one. Keep a type hint with a JSDoc comment if you want editor help.
git mv jest.config.ts jest.config.js
# jest.config.js
/** @type {import('jest').Config} */
module.exports = {
verbose: true,
};3Verify
Run the tests.
npx jestConfirmed by jestjs.io
How do I stop it coming back?
- Keep ts-node (or the loader you chose) in devDependencies next to jest.
- Run npx jest --showConfig in CI as a cheap check that the config loads.
- Use a JavaScript config in repos where you do not already run ts-node.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Back end
TypeScript cannot find '@angular/platform-browser' in an Angular project
Cannot find module '@angular/platform-browser' or its corresponding type declarations.
TS2307 means TypeScript could not turn the import into a file.
3 causes, each with a fixBack end
Angular build fails with TS2707 or "has no exported member" after installing a library
Module '"@angular/core"' has no exported member
These errors mean a library was compiled by a newer Angular than your app uses.
3 causes, each with a fixBack end
cdk synth says --app is required
--app is required either in command-line, in cdk.json or in ~/.cdk.json
The CDK CLI needs a command that runs your app and finds it in three places: the --app option, cdk.json in the project folder, or cdk.json in your home folder.
3 causes, each with a fixBack end
TypeScript cannot find module '@nestjs/core' or its type declarations
error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.
TS2307 means TypeScript searched node_modules and found neither the package nor its types.
3 causes, each with a fixBack end
Mocha or Node cannot find ts-node/register
Error: Cannot find module 'ts-node/register'
Node resolves ts-node/register from your project's node_modules, so the package must be installed there, next to typescript.
2 causes, each with a fixBack end
TypeError: Class constructor cannot be invoked without 'new' in compiled TypeScript
TypeError: Class constructors cannot be invoked without 'new'
Node.js throws this when a native class is called like a plain function.
2 causes, each with a fix