-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Typechecking types generated by prisma causes RangeError: Maximum call stack size exceeded
#8535
Comments
Can you share the schema maybe? That would be best for a reproduction on our side so we can just start debugging vs. first trying to find a reproduciton. |
Also, please try again with latest version. 2.19 is bit old now. |
Hi, I am @dansworkaccount's coworker and can provide some more information. Unfortunately, our codebase is private so we cannot share it here.
Currently, we are trying to debug tsc to try to get better information on the issue, but that is not something we have experience with before, so it is a difficult process. If you have any suggestions we would greatly appreciate it. |
@janpio I was able to put together a private repository with a minimal reproduction using our schema. Is it possible for me to share this with someone on the Prisma team to review? I believe I have narrowed the bug down to an excessively deep type instantiation stack caused by the custom XOR type on a schema of sufficient size, more specifically, with a model with a sufficient number of relationships. |
@pantharshit00 can take a look for sure. Are you sure this is caused by Prisma and not by Nexus by the way? |
thank you @janpio. Yes I am sure it is Prisma. My reproduction uses the quick start from prisma docs as the frame. It is Prisma 2.28, with my organization's schema and a single function. @pantharshit00 I have provided access to the repository for you. Please let me know if you have any issues working with it. To provide some more information, I can share some of the research I have done. The reason I believe it is related to the XOR type is from debugging tsc and watching the stack grow until blowing with a ton of XOR frames. I looked at the code for that type which references a stack overflow post, which references issue 14094 in the Typescript repository. That led me to issue 23777 in the Typescript repository which sounds very similar. Let me know if you have any other questions about it. |
For what it's worth, we've recently started to encounter this issue also. We are using Prisma 2.21 and do not use Nexus. We use introspection to build our schema from a Postgres DB. The schema has 124 models with many relationships and 15 enum types. We thought it might be a Node.js compatibility issue so we downgraded to Node 14.4 and that seemed to help for a little while. But we recently added a few more models, with relationships, to our schema and are experiencing this issue with Node 14.4 now, too. I can share the schema, if needed, but it needs to be treated as sensitive information and made available only to those who have a need to see it. |
@janpio @pantharshit00 Has anyone at Prisma been able to look into this issue yet? Our schema has grown enough to reach our initial increased stack limit. |
Which version of TypeScript are you currently using? Does this work with other versions? |
We are currently using TypeScript version 4.2.4. We have tested the most recent version 4.4.3 and the error is still present |
This comment from TypeScript repo could help debug what's happening here maybe |
Yes, I have looked at a number of TypeScript issues, that one included, to find debugging steps, which is how I came to the conclusion that this particular issue is caused by the XOR implementation. I have a private repo with minimal reproduction and debugging instructions that I invited @pantharshit00 to. I can invite others from the Prisma team as well if that would be helpful, it is using my company's schema so I cannot share it publicly, unfortunately. I would also be happy to share more information on the research I have already done, I have tried to keep the information I have included so far as closely relevant as possible so as not to spam... |
Hello @rs-payres Sorry for the late reply here. I had to take some time off last week and I wasn't able to get back here on time to accept the repository invitation. Can you please send that again 🙏 ? |
Note: would be interesting to reproduce with TypeScript version v4.5-beta: https://github.com/microsoft/TypeScript/releases/tag/v4.5-beta and see is result is the same. |
We get the same issue with prisma 3.2.1 and typescript 4.4.4, switching back to prisma 3.1.1 and typescript 4.2.3 is working. |
@Jolg42 I tested my reproduction repo last night on the 4.5 beta and it has the same issue. I looked at the PR for tail-recursion type check ejection before and, while it looks related, it doesn't cover this specific scenario because it is not caught by their previous safety measures. |
Hey @rs-payres, can you please invite me to your repro? |
Can you please contact me for an NDA? We use the same prisma schema for two backends. The smaller ones tsc compiles fine with prisma up to 3.5 but for the larger backend no version higher than 3.1.1 compiles. |
Hi @Bjoernstjerne could you contact us at [email protected] so we can handle this privately? NDA is no problem of course. |
Hi there, we are experiencing the same issue with typescript 4.4.3 and prisma 3.4.0 when running a |
This may be a different issue, but I'm getting
Actually I created that model with a kind of an accident, and it looks very error-prone. Something that would cause an infinite loop. And it did. |
I'm having the same issue. It also seems to be related to the generic The generated prisma types in my project is currently ~165000 LOC, and I suspect the following self referential model is the breaking point, as the generated types is very complex and creates an infinite loop: model Folder {
id String @id @default(cuid())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
path String
homeId String @map("home_id")
authorId String? @map("author_id")
files File[]
home Home @relation(fields: [homeId], references: [id], onDelete: Cascade)
author User? @relation(fields: [authorId], references: [id])
subFolders Folder[] @relation("FolderToFolder")
parentFolder Folder? @relation("FolderToFolder", fields: [parentFolderId], references: [id], onDelete: Cascade)
parentFolderId String? @map("parent_folder_id")
@@unique([homeId, path])
@@map("folders")
} See for example: I've emailed the full Is there any workaround for this? PS. I'm using Prisma 4.6.1 and have tried upgrading to latest typescript version etc. without success. Edit: Increasing the node stack size seems to have "fixed" the problem for me. It seems like the generated Prisma types will break a NodeJS Typescript project once it reaches a certain size unless you increase the node stack-size...? |
I'm experiencing this as well. Was causing silent errors in I only have 14 models and experience the same issue. Did some debugging of this issue last night and also found that it seems to occur with an XOR, although unclear if that's the actual issue. Increasing stack size does not seem like a long-term solution, and I assume it's slowing down type checking in the meantime. |
Hey @demipixel can you please share a reproduction with us? |
I'll see what I can do. I tried extracting just the schema alone and can't seem to replicate, so must be due to how I'm using the types. |
Is this still reproducible when upgrading to Prisma |
@Jolg42 yes, the problem still reproducible, i'm currently using this version and still get the error. I'm working in another project that runs both in windows 10 and Debian 12. |
@KevNik could you please share a reproduction with us? |
Sorry for the late response. After some work, i figured it out. I was trying to save a bigger Json string than the psql could acttaually handle. It was an error object from axios. You can reproduce this just by making a simple axios request and force it to get a error, in my case, the testEndpoint was not online
|
Hi @KevNik, thanks for your reproduction. Can you please share which TypeScript version you used? |
Sorry, i'm not using TypeScript.
|
RangeError: Maximum call stack size exceeded
@KevNik since your issue is at runtime and not about types, could you please create a separate issue? |
Since we haven't received a reproduction and given the age of this issue (reported for |
Bug description
When typechecking the types that are generated by prisma cause an error
RangeError: Maximum call stack size exceeded
. This error occurs with typechecking with ts-node, or tsc.How to reproduce
prisma generate
tsc --noEmit
Expected behavior
tsc
is able to complete without a stack errorPrisma information
The schema has about ~115 models and ~40 enums.
Environment & setup
This the environment of my local machine but the error is occurring on other machines and cicd pipeline
Prisma Version
We are currently working on upgrading to the newest version and moving away from the nexus-plugin-prisma
The text was updated successfully, but these errors were encountered: