ts-jest: ts-jest doesn't respect outDir and rootDir when using project references
🐛 Bug Report
In a monorepo setup, that uses ts project references, it is possible to get ts-jest to compile child project refs so that tests in the parent project run in jest. This is evident in the repro repository here: https://github.com/Martaver/ts-jest-issue-805-demo which, when you clone and run yarn test navigates my-app’s dependency on my-library successfully and compiles and runs the tests.
In this example, index.ts is in the root directory of each project reference and they use the default main entry in package.json, which is index.js.
Most repositories though, keep code under /src, and one of the features of project references is the ability to map a javascript main entry point in package.json back to the originating typescript entry. It can do this through outDir and rootDir.
However, when moving all code to /src and adding ourDir and rootDir configurations to tsconfig.json and setting the corresponding main in package.json of each project reference, the path resolution fails and the following error is revealed:
Cannot find module '@mfellner/my-library' from '../my-app/src/main.ts'
Unless I’m misconfiguring something, it appears ts-jest isn’t honouring tsc’s project resolution behaviour.
Note that tsc -b works fine (executed in packages/my-app for instance).
To Reproduce
Steps to reproduce the behavior:
- Clone https://github.com/Martaver/ts-jest-issue-805-demo/
- Switch to branch: repro-ts-jest-outDir-rootDir
- Run
yarn test… you will notice thatmy-appfails because it can’t loadmy-library.
Expected behavior
ts-jest to successfully load the my-library module from the project reference, as it does when index.ts is in the root of each project.
Link to repo (highly encouraged)
https://github.com/Martaver/ts-jest-issue-805-demo/ branches:
- repro-ts-jest-outDir-rootDir (demonstrates error)
- master (demonstrates working project ref test, in root of project reference)
Debug log:
N/A
envinfo
System:
OS: macOS 10.14.6 (18G4032)
Npm packages:
jest: 26.0.1
ts-jest: 26.1.0
typescript: 3.9.3
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 21
I know this is an old issue, but if anyone else is running into similar problems… I just made this on Jest config and it worked for me: