-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ts-jest doesn't respect outDir and rootDir when using project references #1698
Comments
also because of microsoft/TypeScript#37239 is not yet in TypeScript 3.9 so for now loading |
The difference is quite specifically when the code sits in a non-default I just tried with No joy with |
hmm I have no idea about that microsoft/TypeScript#37239 in which build :( |
In the mean time, a workaround is to use jest's E.g. in each individual project's
@ahnpnl it's worth noting that I tried |
Btw would you please try to create the debug log with typescript@next or dev ? To create the debug log, the instruction is in the issue template. From debug log, it will be possible to check which path of tsconfig was loaded and what is the final config. |
Sure, I tried that but I'm not getting a
scratches head somewhat confused |
I think you need to do: export TS_JEST_LOG=ts-jest.log . For me I need to do that to make it work with my Mac 😅 |
Ah! Yes... me mac good. |
For
|
For
|
From dev: readTsConfig(): reading /Users/martaver/Projects/forks/ts-jest-issue-805-demo/packages/my-app/tsconfig.json "tsconfig”: {"outDir":"/Users/martaver/Projects/forks/ts-jest-issue-805-demo/packages/my-app/dist","rootDir":"/Users/martaver/Projects/forks/ts-jest-issue-805-demo/packages/my-app/src","projectReferences":[{"originalPath":"../my-library","path":"/Users/martaver/Projects/forks/ts-jest-issue-805-demo/packages/my-library"}], "raw":{"outDir":"dist","preserveSymlinks":false,"rootDir":"src","tsBuildInfoFile":"dist/.tsbuildinfo"},"extends":"../../tsconfig.json","include":["src/**/*"],"references":[{"path":"../my-library"}]}, Look like tsconfig was resolved correctly with outDir and rootDir. Cannot find module issue can be also related to jest that jest cannot find the module based on the path. |
If you get error cannot find module, this can be either:
|
Is that with dev or next? |
Why would jest not be able to resolve it, if the paths are all fine? |
From next "readTsConfig(): reading /Users/martaver/Projects/forks/ts-jest-issue-805-demo/packages/my-library/tsconfig.json" "tsconfig""outDir":"/Users/martaver/Projects/forks/ts-jest-issue-805-demo/packages/my-library/dist","rootDir":"/Users/martaver/Projects/forks/ts-jest-issue-805-demo/packages/my-library/src", "raw":"outDir":"dist","rootDir":"src","sourceMap":true,"tsBuildInfoFile":"dist/.tsbuildinfo"},"extends":"../../tsconfig.json","include":["src/**/*"]},"typeAcquisition":{"enable":false,"exclude":[],"include":[]},"wildcardDirectories":{"/users/martaver/projects/forks/ts-jest-issue-805-demo/packages/my-library/src":1}} I can see between Did you run
Jest relies on |
Yep, from root directory. It also fails with the same error if I run jest directly from It would be nice to not have to use nodeModuleMapper here... especially since the case where |
So I debugged a bit: In general, both Then I checked the
as you can see, the line Moreover, you can see in error stack trace:
This comes from jest module resolution. |
I have actually an idea, might be a new feature for ts-jest that leverage the usage of AST transformer. At the moment, ts-jest only has one ast transformer which is for hoisting some jest stuffs. One can create another transformer which will alter the statement require("@mfellner/my-library") to require (<path_resolved_via_typescript_module_resolution>). IMO, by doing this, it is possible to avoid configure moduleNameMapper You can also write your own ast transformer and give it to ts-jest config. |
i will close this as not Related infor you can find here microsoft/TypeScript#15479 (comment) |
I know this is an old issue, but if anyone else is running into similar problems... globals: {
'ts-jest': {
isolatedModules: true,
},
} |
🐛 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
navigatesmy-app
's dependency onmy-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 defaultmain
entry inpackage.json
, which isindex.js
.Most repositories though, keep code under
/src
, and one of the features of project references is the ability to map a javascriptmain
entry point inpackage.json
back to the originating typescript entry. It can do this throughoutDir
androotDir
.However, when moving all code to
/src
and addingourDir
androotDir
configurations totsconfig.json
and setting the correspondingmain
inpackage.json
of each project reference, the path resolution fails and the following error is revealed:Unless I'm misconfiguring something, it appears
ts-jest
isn't honouring tsc's project resolution behaviour.Note that
tsc -b
works fine (executed inpackages/my-app
for instance).To Reproduce
Steps to reproduce the behavior:
yarn test
... you will notice thatmy-app
fails because it can't loadmy-library
.Expected behavior
ts-jest
to successfully load themy-library
module from the project reference, as it does whenindex.ts
is in the root of each project.Link to repo (highly encouraged)
https://github.com/Martaver/ts-jest-issue-805-demo/
branches:
Debug log:
envinfo
The text was updated successfully, but these errors were encountered: