Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Jest will not load jest.config.ts

ErrorFailed to parse the TypeScript config file

Short 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.

  • Applies to Jest 29, Jest 30, ts-node 10, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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-register
  2. 2Match what you see, then jump to its fix

    1. 1npm ls shows no ts-node, or the message mentions ts-nodets-node is not installedFix
    2. 2The wrapped error is a TypeScript or module error raised while loading the configts-node cannot compile the file in your project setupFix
    3. 3A loader chain is the only thing standing between you and a green runYou do not need a TypeScript config at allFix

What does the error look like?

  • Failed to parse the TypeScript config file
  • Jest: 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-node

2Fix

Add ts-node as a dev dependency.

npm install --save-dev ts-node

3Verify

Run Jest.

npx jest --showConfig

Confirmed by jestjs.io

Did this fix it?

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.ts

2Fix

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 --showConfig

Confirmed by jestjs.io

Did this fix it?

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 jest

Confirmed by jestjs.io

Did this fix it?

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:

Related fixes

Back 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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.