-
Notifications
You must be signed in to change notification settings - Fork 458
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
Can't seem to use with linked typescript package #424
Comments
I've solved this problem temporarily by importing |
I don't think I understand what you mean with a linked package. Can you provide a minimal repo? |
@Anupheaus it sounds like you were trying to use ts-jest without installing it. Is that correct? |
Nope, I installed it in the main package and I mean an |
that's weird. A minimal repo would be very welcome because it's hard to 'imagine' what could be causing this |
Sorry for the inactivity! @kulshekhar I wonder if you meant "globally installed"? I didn't globally install ts-jest, I assumed that it would work automatically in linked packages (within node_modules) but that could be a false assumption and it needs to be installed globally in order to do that? Is that right? |
@Anupheaus I didn't mean 'globally installed'. My first thought was that maybe ts-jest wasn't installed in your project (but as you pointed out, that was incorrect) If you can create a minimal repo that replicates this issue, I'll be happy to reopen this and take a look at it |
If I get time tonight I will certainly do that! |
Okay, so I am having the same issue. I installed ts-jest in the linked dependency and the error changed to:
|
Do you have jest installed in the project? Please provide a minimal reproducible repo. |
Jest, and ts-jest are installed in both the main project, and the npm-linked dependency. However I don't see why whatever is installed in the linked dependency should matter. We're not testing the dependency, we're testing components that are just importing and using something from it. What would a minimal reproducible repo with a linked dependency look like? |
In my main project the stack trace indicates the error origin being ts-jest in the linked dependency. Should it be even looking for ts-jest in the linked dependency?
|
What exactly do you mean with linked dependency? |
Okay, I haven't explained myself thoroughly, sorry. Let me paint you a picture, maybe this will help: Let's say I have a React project called "MainProj" and I have a separate project that handles all of the communication to my back-end called "DataClient" which is hosted on an internal repository -- both written in typescript -- and the latter is a dependency of the former. I need to work on a new component in MainProj, which will need to get new data from the back-end and as such, I have to create a new service in my DataClient. So between the two I use npm link to link the project DataClient into my MainProj. However whenever when I develop the feature on both projects and everything seems working, I start writing unit tests for my component, none of them work, and the aforementioned errors are shown. Now I may have tests using Jest and ts-jest inside my DataClient dependency or I may not, but that's not supposed to matter here. The important thing to note is that both Jest and ts-jest are installed in my MainProj, where only the tests that are importing the DataClient dependency are failing with said errors. This only happens when I have used If anything isn't clear please don't hesitate to ask, I'll be more than happy to explain as I've been trying to understand what's happening for a while now. |
Might this be related to jestjs/jest#5085? |
Yeah I don't think it's on our end - we just transpile the code jest gives us. |
Yeah, I figured as much... anyway I'll keep an eye on the next Jest release and see if it helps. Thanks |
I had a similar problem and found a fix. I think it occurs because Jest is looking for I solved it by setting the "node_modules" folder explicitly on the Jest config file using the line bellow:
|
Thanks @acaua! This seems to be suddenly afflicting my I explicitly added this to a moduleDirectories: ['<rootDir>/node_modules', '<rootDir>/../../node_modules'], (which I expect is the default behavior) and it fails. Change that to: moduleDirectories: ['<rootDir>/../../node_modules'], and all is well. I'm not sure how this corner case appears but I wouldn't expect this workaround to be needed. |
So this came around and bit me again. My ^^^workaround started causing node_module resolution failures. I removed the |
@rosskevin your issue if it is an issue is a jest issue. |
I have a project with a linked TypeScript package but when I run the tests they all fail with:
Cannot find module 'ts-jest' from 'index.ts'
I have followed the configuration advised to make imported TypeScript packages work and I would expect it to transpile the code within the imported package as well.
I will try and create one
Here is my package.json config:
The imported package is
@personal/common
.The tests fail when it tries to parse
...node_modules/@personal/common/index.ts
so I know it is something to do with ts-jest not being used on the imported package.my ts-config configuration is:
The text was updated successfully, but these errors were encountered: