kulshekhar / ts-jest

A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.
https://kulshekhar.github.io/ts-jest
MIT License
6.97k stars 453 forks source link

[Bug]: node16 moduleResolution no longer works since 29.2.4 #4552

Open skrtheboss opened 1 month ago

skrtheboss commented 1 month ago

Version

29.2.5

Steps to reproduce

  1. Clone my repo at https://github.com/skrtheboss/ts-jest-node16-module-resolution
  2. Run pnpm install
  3. Run pnpm nx run eslint-rules:test --skip-nx-cache --no-cache
  4. The command should fail with:
    
    > nx run eslint-rules:test --no-cache

jest --no-cache

FAIL eslint-rules rules/my-custom-rule.spec.ts ● Test suite failed to run

rules/my-custom-rule.ts:18:31 - error TS2307: Cannot find module '@typescript-eslint/utils/ast-utils' or its corresponding type declarations.

18 import { isTypeKeyword } from '@typescript-eslint/utils/ast-utils';
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PASS eslint-rules rules/a-my-custom-rule.spec.ts

Test Suites: 1 failed, 1 passed, 2 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 4.012 s Ran all test suites. Warning: command "jest --no-cache" exited with non-zero status code —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

NX Ran target test for project eslint-rules (6s)

  With additional flags:
    --cache=false

✖ 1/1 failed ✔ 0/1 succeeded [0 read from cache]


### Expected behavior

1. Clone my repo at https://github.com/skrtheboss/ts-jest-node16-module-resolution
3. Checkout branch with older version `git checkout fix/ts-jest-29-2-3` or `git checkout fix/ts-jest-29-1-0`
2. Run `pnpm install`
4. Run `pnpm nx run eslint-rules:test --skip-nx-cache --no-cache`
5. The command will succed with:

nx run eslint-rules:test --no-cache

jest --no-cache

PASS eslint-rules rules/my-custom-rule.spec.ts ● Console

console.log
  false

  at create (rules/my-custom-rule.ts:36:13)
      at Array.forEach (<anonymous>)

PASS eslint-rules rules/a-my-custom-rule.spec.ts

Test Suites: 2 passed, 2 total Tests: 2 passed, 2 total Snapshots: 0 total Time: 4.097 s Ran all test suites.


### Actual behavior

Tests fail since exports field of `@typescript-eslint/utils` package is not taken into consideration while resolution is performed

### Debug log

Content is too long.

### Additional context

As far as I can tell, the commit that breaks this is https://github.com/kulshekhar/ts-jest/commit/70b9530.

### Environment

```shell
System:
    OS: Linux 6.10 Arch Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
    pnpm: 9.10.0 - ~/.nvm/versions/node/v20.17.0/bin/pnpm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
skrtheboss commented 1 month ago

ts-jest.log

ahnpnl commented 1 month ago

Hi, we reverted the change because it caused breaking change. We will introduce a temporarily flag to support this.

A suggested flag name is useModernResolution

Duplicated with #4198

skrtheboss commented 1 month ago

Hi @ahnpnl, Thank you for the feedback! I should have found this issue myself 🤦‍♂️. I'm okay with whatever you think is best!