Skip to content

Large schemas generate huge index.d.ts causing slow autocomplete and type-checking in your editor #4807

Open

Description

@andrehsu

Problem

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.

Activity

  1. matthewmueller commented on Jan 7, 2021

    @matthewmueller
    Contributor

    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:

    1. Feel the pain. A video demonstrating the slowness in your IDE would be very helpful for us.
    2. 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.

  2. MattGson commented on Jan 20, 2021

    @MattGson

    @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.

  3. mribichich commented on Feb 10, 2021

    @mribichich

    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.

  4. seamory commented on May 11, 2021

    @seamory

    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.

  5. added
    topic: client types
    on May 11, 2021
  6. maximkott commented on Jul 12, 2021

    @maximkott

    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! 😃

  7. maximkott commented on Jul 12, 2021

    @maximkott

    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.

  8. seamory commented on Jul 13, 2021

    @seamory

    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.

    Snipaste_2021-07-13_08-55-15

    Hope it's helpful.

  9. michael-land commented on Jul 13, 2021

    @michael-land

    It would be nice user can disable features to avoid generate unused types

    generator client {
      provider        = "prisma-client-js"
      previewFeatures = ["nApi"]
      disableFeatures = ["filterJson", "orderByAggregateGroup"]
    }
  10. 160 remaining items

  11. dbrxnds commented on Jul 21, 2025

    @dbrxnds

    @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.

    See repro: https://github.com/dbrxnds/prisma-internal-package-repro

    1. Clone and install
    2. Run dev
    3. Open packages/nested-package/src/index.ts

    Notes:

    • 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.
  12. nurul3101 commented on Aug 18, 2025

    @nurul3101
    Contributor

    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.
    
    Image
  13. FGoessler commented on Aug 21, 2025

    @FGoessler
    Contributor

    @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.

  14. FGoessler commented on Aug 21, 2025

    @FGoessler
    Contributor

    @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.

  15. luismsrodrigues commented on Aug 28, 2025

    @luismsrodrigues

    @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?

    import { FindManyWithPaginationDto } from '@/core/database/dtos/find-many-with-pagination.dto';
    import {
      ChangeWhereInputValueToBoolean,
      DatabaseHelper,
    } from '@/core/database/helper';
    import { Prisma } from '@generated/prisma/client';
    
    export const findManyAsPageExtension = Prisma.defineExtension({
      name: 'findManyAsPage',
      model: {
        $allModels: {
          async findManyAsPage<
            TModel,
            TArgs extends Prisma.Args<TModel, 'findMany'>,
          >(
            this: TModel,
            { skip = 0, take = 30 }: { skip?: number; take?: number },
            args?: Prisma.SelectSubset<TArgs, Prisma.Args<TModel, 'findMany'>>,
            search?: {
              searchTerm: string;
              selector: ChangeWhereInputValueToBoolean<
                Prisma.Args<TModel, 'findMany'>['where']
              >;
            },
          ): Promise<
            FindManyWithPaginationDto<Prisma.Result<TModel, TArgs, 'findMany'>>
          > {
            const context = Prisma.getExtensionContext(this);
            const where = (args as any)?.where || {};
    
            if (search && search.searchTerm) {
              const addInsensitiveSearchResult =
                DatabaseHelper.addInsensitiveFilterSearch<TArgs['where']>(
                  search.searchTerm,
                  search.selector,
                );
    
              if (addInsensitiveSearchResult) {
                where.AND = [
                  ...((where.AND as any[]) || []),
                  ...addInsensitiveSearchResult,
                ];
              }
            }
    
            const total = await (context as any).count({
              where: where,
            });
    
            const entities =
              skip >= total || take == 0
                ? []
                : await (context as any).findMany({
                    ...(args as any),
                    where: where,
                    take: take,
                    skip: skip,
                  });
    
            return {
              entities: entities,
              total: total,
              take: take,
              skip: skip,
            };
          },
        },
      },
    });
  16. CamdenClark commented on Aug 29, 2025

    @CamdenClark

    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.

  17. luismsrodrigues commented on Aug 29, 2025

    @luismsrodrigues

    when i remove the https://github.com/HRM/prisma-nitro-patcher i have deep stack error with the latest version of prisma

  18. itspers commented on Sep 13, 2025

    @itspers

    @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...

  19. aarhusgregersen commented on Sep 15, 2025

    @aarhusgregersen

    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.
    
    Image

    It seems like this part of the issue is resolved with Prisma 6.16.1. At least it is on our end.

  20. itspers commented on Feb 3, 2026

    @itspers

    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

  21. AnkurPrabhu commented on Feb 4, 2026

    @AnkurPrabhu

    Hey, I’ve been using tsgo and it’s improved a lot give it a try, it really helped me.

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions