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.