ts-jest doesn't respect outDir and rootDir when using project references
See original GitHub issueš 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-app
fails 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
Issue Analytics
- State:
- Created 3 years ago
- Comments:21
Top GitHub Comments
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:
i will close this as not
ts-jest
issue becausets-jest
doesnāt actually perform module resolution but that isjest
does. You should look into TypeScript plugin which can rewrite paths, something likettypescript
does.Related infor you can find here https://github.com/microsoft/TypeScript/issues/15479#issuecomment-468122916