You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Large schemas generate huge index.d.ts causing slow autocomplete and type-checking in your editor #4807
Whenever I generate the prisma client again after modifying the schema, it takes a while for WebStorm (an IntelliJ-based IDE) to reflect the changes in static analysis. While I haven't done any benchmarking to confirm this is the case, I think it is because
of the thousand lines long index.d.ts. Seeing as the draw of Prisma is that it is typed, I feel like an improvement in the static analysis performance would be relevant to the project.
Suggested solution
Split the index.d.ts file into separate type-def files for potentially faster static analysis.
Reacted by Matias Ribichich, Ollie Chick, Maxim Kot, Michael Li, Toni Villena, Eric Wooley, KhanhHH, Brian Levine, Morb, Ilya Gorbachevsky and 97 more
We have started thinking of ways to first measure our Typescript type-check performance, but so far it hasn't been prioritized.
Ideas for next steps:
Feel the pain. A video demonstrating the slowness in your IDE would be very helpful for us.
Figure out a solution (maybe split files, reduce type generation, etc.). One thing to try would be to break out the types into separate files and link them up by hand. If it proves to be a lot faster, that tells us this change is worth doing.
Any help with 1. and/or 2. would accelerate fixing this problem.
@matthewmueller I have a slightly stronger use case for this. Our prisma index.d.ts file is over 400,000 lines long. At this size, Webstorm and VSCode both stop linting entirely and many other related functions stop working such as auto-completion on types. A sensible solution would probably be to split the types up into one file per table. From my experience, both IDEs can easily handle hundreds of files well but cannot handle very long files.
Reacted by Andre Hsu, Jan Piotrowski, Ashlynne Mitchell, Matt, Ollie Chick, Evan, Gerrit Alex, Eric Wooley, Brian Levine, Yasser Nascimento and 12 more
I have another use case, similar to frontend projects.
I've been trying to use prisma client in our BE project, but people are still reluctant to use it, so we've been only using the types and enums from prisma.
The thing is since we use webpack, and all the prisma types and enums are in the same file as the client, even if you dont use the client, webpack bundles everything from the file (node_modules/.prisma/client/index.js).
So having 3 separate files would solve everyone's problem:
one file for the client implementation
one/multiple files for the types (it could also have a index to re-export them all)
one file for the enums
It seems to be a fairly easy change to make, without any functionality change. it's just a file organization.
Also for the prisma client files, tree shacking doesn't work. So even if you import one enum you get everything.
Even putting the dmmfString const would reduce 1.5MB from the import.
A slightly different use case here: I wan't to build and bundle my app into *.js and *.d.ts files and I want my models to be part of it, without any notion of prisma. Simply re-exporting my models will not work, since prisma is treated as an external module. Forcing typescript to include prisma models into the build, leads to compilation of tens of thousands of lines of code/types that are not necessary. This happens simply because models and other prisma types are in the same file. Besides that, I was not able to get the build working because something always causes an error within prisma files.
I don't see an easy workaround for this as of yet. The current setup is really limiting, unfortunately. All I want is to include those 200 lines of types without being forced to process additional 30k lines that never tend to compile.
This is the only issue I have with Prisma so far, it's really awesome otherwise! 😃
My current workaround is to copy & paste models from prisma (they are almost at the top of node_modules/.prisma/client/index.d.ts) to a file called models.ts. Then I make sure that I import all my model types from the models.ts file, rather than from @prisma/client directly. The downside is that you have to copy & paste those models again after every schema change 😆
Maybe this helps someone.
Reacted by KhanhHH, Rubens Mariuzzo and Matthew Halloran
Hello, i found the cause why webstorm or idea spend to much time to analyse, but no result. you need to symbol the path .\node_modules.prisma with your project as resources or sources in Project structure in Modules in Project Setting Tab.
As follow pic.
Hope it's helpful.
Reacted by Ilya Gorbachevsky, Nathan P. Bombana, Salvatore and nick-heard
@FGoessler Not sure if this is worthy of a new github issue, but running into an issue where re-exporting code from a monorepo workspace that in turn uses the Prisma related package inside it isn't possible with the prisma-client generator.
Error:
TS2742: The inferred type of 'SomeTRPCRouter' cannot be named without a reference to '[monorepo workspace path]/dist/generated/internal/prismaNamespace'. This is likely not portable. A type annotation is necessary.
I am aware that you can disable declaration, but I would really rather not because that too really helps TS performance in large repo's.
In the repro, you can just re-export prismaNamespace as a (temporary) fix, but that does not work in our codebase. It seems there's certain duplicate types that don't play nice together. But its difficult to figure out what they are, so I haven't gotten to that.
I tried reproduction from @dbrxnds and can confirm the error:
The inferred type of 'FooBar' cannot be named without a reference to '../node_modules/@repo/database/generated/client/internal/prismaNamespace'. This is likely not portable. A type annotation is necessary.
@luismsrodrigues we shipped some significant type performance improvements with the latest 6.14.0 release when using the new prisma-client generator. Other than that @ToyB0x 's suggestion around using the typeof operator should also provide very significant speedups in type check performance such that even without 6.14.0 (or in certain edge cases under 6.14.0) you still have fast and reliable type resolving.
Is there a recommended migration path for the new client generator? We have hundreds of imports across our application that would be tricky to do in one fell swoop.
We could run both generators during a migration period but that makes the problem worse temporarily.
Any recommended path here? Couldn't find anything in the generator docs.
@FGoessler what is general plan there? Like how fast 'old' generator will become deprecated and eventually i will not be able to update? I afraid that eventually skipping prisma updates will lead to some unresolvable dependencies conflict in package.json, maybe need to start planning migration to some other ORM already...
I tried reproduction from @dbrxnds and can confirm the error:
The inferred type of 'FooBar' cannot be named without a reference to '../node_modules/@repo/database/generated/client/internal/prismaNamespace'. This is likely not portable. A type annotation is necessary.
It seems like this part of the issue is resolved with Prisma 6.16.1. At least it is on our end.
Ok i think i reached point where i literally can't work on project anymore because of this - i just dont have enough RAM. Did anybody find a way to migrate from Prisma to something reasonable? In this era of AI i dont really care about DX
Activity
matthewmueller commentedon Jan 7, 2021
Hey @andrehsu! Thanks for raising this issue.
We have started thinking of ways to first measure our Typescript type-check performance, but so far it hasn't been prioritized.
Ideas for next steps:
Any help with 1. and/or 2. would accelerate fixing this problem.
MattGson commentedon Jan 20, 2021
@matthewmueller I have a slightly stronger use case for this. Our prisma index.d.ts file is over 400,000 lines long. At this size, Webstorm and VSCode both stop linting entirely and many other related functions stop working such as auto-completion on types. A sensible solution would probably be to split the types up into one file per table. From my experience, both IDEs can easily handle hundreds of files well but cannot handle very long files.
mribichich commentedon Feb 10, 2021
I have another use case, similar to frontend projects.
I've been trying to use prisma client in our BE project, but people are still reluctant to use it, so we've been only using the types and enums from prisma.
The thing is since we use webpack, and all the prisma types and enums are in the same file as the client, even if you dont use the client, webpack bundles everything from the file (node_modules/.prisma/client/index.js).
So having 3 separate files would solve everyone's problem:
It seems to be a fairly easy change to make, without any functionality change. it's just a file organization.
Also for the prisma client files, tree shacking doesn't work. So even if you import one enum you get everything.
Even putting the dmmfString const would reduce 1.5MB from the import.
seamory commentedon May 11, 2021
I have the same question. static analysis use a lot of memory but not have any result, becase of the tens of thousands of lines in index.d.ts.
maximkott commentedon Jul 12, 2021
A slightly different use case here: I wan't to build and bundle my app into
*.jsand*.d.tsfiles and I want my models to be part of it, without any notion of prisma. Simply re-exporting my models will not work, since prisma is treated as an external module. Forcing typescript to include prisma models into the build, leads to compilation of tens of thousands of lines of code/types that are not necessary. This happens simply because models and other prisma types are in the same file. Besides that, I was not able to get the build working because something always causes an error within prisma files.I don't see an easy workaround for this as of yet. The current setup is really limiting, unfortunately. All I want is to include those 200 lines of types without being forced to process additional 30k lines that never tend to compile.
This is the only issue I have with Prisma so far, it's really awesome otherwise! 😃
maximkott commentedon Jul 12, 2021
My current workaround is to copy & paste models from prisma (they are almost at the top of
node_modules/.prisma/client/index.d.ts) to a file calledmodels.ts. Then I make sure that I import all my model types from themodels.tsfile, rather than from@prisma/clientdirectly. The downside is that you have to copy & paste those models again after every schema change 😆Maybe this helps someone.
seamory commentedon Jul 13, 2021
Hello, i found the cause why webstorm or idea spend to much time to analyse, but no result. you need to symbol the path .\node_modules.prisma with your project as resources or sources in Project structure in Modules in Project Setting Tab.
As follow pic.
Hope it's helpful.
michael-land commentedon Jul 13, 2021
It would be nice user can disable features to avoid generate unused types
160 remaining items
dbrxnds commentedon Jul 21, 2025
@FGoessler Not sure if this is worthy of a new github issue, but running into an issue where re-exporting code from a monorepo workspace that in turn uses the Prisma related package inside it isn't possible with the
prisma-clientgenerator.Error:
See repro: https://github.com/dbrxnds/prisma-internal-package-repro
packages/nested-package/src/index.tsNotes:
declaration, but I would really rather not because that too really helps TS performance in large repo's.prismaNamespaceas a (temporary) fix, but that does not work in our codebase. It seems there's certain duplicate types that don't play nice together. But its difficult to figure out what they are, so I haven't gotten to that.nurul3101 commentedon Aug 18, 2025
I tried reproduction from @dbrxnds and can confirm the error:
FGoessler commentedon Aug 21, 2025
@dbrxnds we have this on our radar and are doing some restructuring of our types right now that should hopefully help to resolve this issue.
FGoessler commentedon Aug 21, 2025
@luismsrodrigues we shipped some significant type performance improvements with the latest 6.14.0 release when using the new
prisma-clientgenerator. Other than that @ToyB0x 's suggestion around using thetypeofoperator should also provide very significant speedups in type check performance such that even without 6.14.0 (or in certain edge cases under 6.14.0) you still have fast and reliable type resolving.luismsrodrigues commentedon Aug 28, 2025
@FGoessler i already upgrade to 6.14.0 and i keep having the same errors the type check is more fast but now
Excessive stack depth comparing types '{ where: { id: string; deletedAt: any; }; select: TaxWarehouseOffloadingSelect<DefaultArgs>; }' and 'TaxWarehouseOffloadingFindFirstOrThrowArgs<InternalArgs & { result: {}; model: { $allModels: { findManyAsPage: () => <TModel, TArgs extends Prisma.Args<TModel, "findMany">>(this: TModel, { skip, take }: { skip?: number; take?: number; }, args?: SelectSubset<TArgs, Args<TModel, "findMany">>, search?: { ...; }) => Pro...'.ts(2321)this is a example of extensions we have on the code, where we doing something wrong here?
CamdenClark commentedon Aug 29, 2025
Is there a recommended migration path for the new client generator? We have hundreds of imports across our application that would be tricky to do in one fell swoop.
We could run both generators during a migration period but that makes the problem worse temporarily.
Any recommended path here? Couldn't find anything in the generator docs.
luismsrodrigues commentedon Aug 29, 2025
when i remove the https://github.com/HRM/prisma-nitro-patcher i have deep stack error with the latest version of prisma
itspers commentedon Sep 13, 2025
@FGoessler what is general plan there? Like how fast 'old' generator will become deprecated and eventually i will not be able to update? I afraid that eventually skipping prisma updates will lead to some unresolvable dependencies conflict in package.json, maybe need to start planning migration to some other ORM already...
aarhusgregersen commentedon Sep 15, 2025
It seems like this part of the issue is resolved with Prisma 6.16.1. At least it is on our end.
itspers commentedon Feb 3, 2026
Ok i think i reached point where i literally can't work on project anymore because of this - i just dont have enough RAM. Did anybody find a way to migrate from Prisma to something reasonable? In this era of AI i dont really care about DX
AnkurPrabhu commentedon Feb 4, 2026
Hey, I’ve been using tsgo and it’s improved a lot give it a try, it really helped me.