0

I'm running into some inconsistent behavior with Jest 30.x, specifically when parsing a jest.config.ts file that imports another TypeScript module, on Node.js 22.18+. My code uses ESM syntax for the Jest config but transpiles it to CommonJS.

  • Node 22.18+ with Jest 29.x - works
  • Node 22.17.x with Jest 30.x - works
  • Node 22.18+ with Jest 30.x - fails

Here's the error on Node 22.18+:

jest
Error: Jest: Failed to parse the TypeScript config file /home/ch/jest-config-module-resolution/jest.config.ts
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/ch/jest-config-module-resolution/createJestConfig' imported from /home/christian-siqueira/jest-config-module-resolution/jest.config.ts
    at readConfigFileAndSetRootDir (/home/ch/jest-config-module-resolution/node_modules/jest-config/build/index.js:2269:13)
    at async readInitialOptions (/home/ch/jest-config-module-resolution/node_modules/jest-config/build/index.js:1147:13)
    at async readConfig (/home/ch/jest-config-module-resolution/node_modules/jest-config/build/index.js:918:7)
    at async readConfigs (/home/ch/jest-config-module-resolution/node_modules/jest-config/build/index.js:1168:26)
    at async runCLI (/home/ch/jest-config-module-resolution/node_modules/@jest/core/build/index.js:1397:7)
    at async Object.run (/home/ch/jest-config-module-resolution/node_modules/jest-cli/build/index.js:656:9)

If I switch to full ESM (adding the .ts extension and adjusting the __dirname implementation), it works on Node 22.18+, but then fails on Node 22.17.

I also tried using a docblock for configuring ts-node but had no success.

Running npx ts-node jest.config.ts works consistently on both Node versions.

This is related to the experimental strip types feature, running Node with the --no-experimental-strip-types flag works.

I've created a repo to easily reproduce this.

3
  • 2
    Given you narrowed it down to 22.17 -> 22.18, did you try disabling the one notable new feature? Please put a minimal reproducible example in the question itself. Commented Sep 24 at 15:32
  • Thanks @jonrsharpe, it indeed works when disabling the experimental strip stripes feature. About the minimal reproducible example, I've added a github repo link in the question, but I'll edit it to make it clearer. Commented Sep 24 at 22:21
  • Solution currently being discussed at: <github.com/jestjs/jest/issues/15837> Commented Sep 27 at 17:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.