prisma: Prisma generate fails on big schema file

Bug description

Hello, my team has found some problems when using prisma generate in our project. When we run npx prisma generate the client responds with an error when stringifying a JSON object, but we can’t see much in the error stack.

We tried running prisma generate in the original version of the project (prisma 2.26.0) and with the latest version (3.10.0 at the day of publishing this issue)

Output when running with version 2.26.0 and DEBUG=“*”:

Environment variables loaded from .env
prisma               : 2.26.0
@prisma/client       : 2.26.0
Current platform     : windows

C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify>dotenv npx prisma generate
  prisma:loadEnv project root found at C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\package.json +0ms
  prisma:tryLoadEnv Environment variables loaded from C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\.env +0ms
[dotenv][DEBUG] "DEBUG" is already defined in `process.env` and will not be overwritten
Environment variables loaded from .env
  prisma:engines using NAPI: false +0ms
  prisma:engines binaries to download query-engine, migration-engine, introspection-engine, prisma-fmt +0ms
Prisma schema loaded from prisma\schema.prisma
  prisma:getConfig Using Query Engine Binary at: C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\prisma\query-engine-windows.exe +0ms
  prisma:getDMMF Using Query Engine Binary at: C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\prisma\query-engine-windows.exe +0ms
  prisma:generator baseDir C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\prisma +0ms
  prisma:generator prismaClientDir C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\@prisma\client +1ms
  prisma:GeneratorProcess 2022-03-09T13:09:52.904Z prisma:client:generator requiredEngine: queryEngine +0ms
  prisma:getGenerators neededVersions {        
  "9b816b3aa13cc270074f172f30d6eda8a8ce867d": {
    "engines": [
      "queryEngine"
    ],
    "binaryTargets": []
  }
} +0ms
  prisma:getGenerators {
  prisma:getGenerators   generatorBinaryPaths: {
  prisma:getGenerators     queryEngine: {
  prisma:getGenerators       windows: 'C:\\Users\\Admin\\Desktop\\Proyectos\\tests\\test-prisma-stringify\\node_modules\\prisma\\query-engine-windows.exe'
  prisma:getGenerators     }
  prisma:getGenerators   }
  prisma:getGenerators } +180ms
  prisma:GeneratorProcess 2022-03-09T13:10:02.791Z prisma:loadEnv skipping package.json at C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\.prisma\package.json +10s
  prisma:GeneratorProcess 2022-03-09T13:10:02.792Z prisma:loadEnv skipping package.json at C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\package.json +0ms
  prisma:GeneratorProcess 2022-03-09T13:10:02.793Z prisma:loadEnv project root found at C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\package.json +1ms       
  prisma:tryLoadEnv Environment variables loaded from C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\.env +0ms
[dotenv][DEBUG] "DEBUG" is already defined in `process.env` and will not be overwritten
Error: Error:
RangeError: Invalid string length
    at JSON.stringify (<anonymous>)
    at respond (C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\@prisma\client\generator-build\index.js:45985:24)
    at LineStream.<anonymous> (C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\@prisma\client\generator-build\index.js:45931:11)


    at _Generate.parse (C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\prisma\build\index.js:65473:17)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async main (C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\prisma\build\index.js:110797:18)

Output running with version 3.10.0 with DEBUG=“*”:

  prisma:engines binaries to download libquery-engine, migration-engine, introspection-engine, prisma-fmt +0ms
  prisma:loadEnv project root found at C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\package.json +0ms
  prisma:tryLoadEnv Environment variables loaded from C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\.env +0ms
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
  prisma:getConfig Using CLI Query Engine (Node-API Library) at: C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\prisma\query_engine-windows.dll.node +0ms
  prisma:getDMMF Using CLI Query Engine (Node-API) at: C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\prisma\query_engine-windows.dll.node +0ms
  prisma:generator prismaCLIDir C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\prisma +0ms
  prisma:generator prismaClientDir C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\@prisma\client +0ms
  prisma:generator baseDir C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\prisma +1ms
  prisma:generator typescriptPath undefined +2ms
  prisma:GeneratorProcess 2022-03-09T13:17:40.083Z prisma:client:generator requiredEngine: queryEngine +0ms
  prisma:getGenerators neededVersions {        
  "73e60b76d394f8d37d8ebd1f8918c79029f0db86": {
    "engines": [
      "queryEngine"
    ],
    "binaryTargets": []
  }
} +0ms
  prisma:getGenerators {
  prisma:getGenerators   generatorBinaryPaths: {
  prisma:getGenerators     queryEngine: {
  prisma:getGenerators       windows: 'C:\\Users\\Admin\\Desktop\\Proyectos\\tests\\test-prisma-stringify\\node_modules\\prisma\\query-engine-windows.exe'
  prisma:getGenerators     }
  prisma:getGenerators   }
  prisma:getGenerators } +212ms
  prisma:GeneratorProcess 2022-03-09T13:17:49.699Z prisma:loadEnv project root found at C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\package.json +10s
  prisma:tryLoadEnv Environment variables loaded from C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\.env +0ms
Error: Error: 
RangeError: Invalid string length
    at JSON.stringify (<anonymous>)
    at respond (C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\@prisma\client\generator-build\index.js:54245:22)
    at LineStream.<anonymous> (C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\@prisma\client\generator-build\index.js:54187:9)


    at Object.parse (C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\prisma\build\index.js:107298:15)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async main (C:\Users\Admin\Desktop\Proyectos\tests\test-prisma-stringify\node_modules\prisma\build\index.js:108740:18)

We will be glad to give you more information if you need it. Thanks for such an amazing ORM

How to reproduce

  1. Create a new npm project
  2. Install prisma and prisma client (npm i prisma and npm i -D @prisma/client)
  3. Run npx prisma generate with a big schema.prisma file (ours has more than 3400 lines and about 162k characters without spaces)
  4. See error

Expected behavior

The prisma client should be able to generate the models from our schema

Prisma information

Unfortunately we can’t give you the schema.prisma that we area using right now. We think that with the information we are giving you, it should be possible to reproduce the same error.

The schema.prisma file has about 3400 lines and 162k characters with a total of 136 models in it.

Environment & setup

We tried with different setups

  • OS: Windows 64 bits and Linux (node image in docker)
  • Database: PostgreSQL
  • Node.js version: v14.17.1, v16.14.0 and v14.19.0

Prisma Version

Executed npx prisma -v The project originally uses prisma version 2, we tried with the latest version but we got the same results

Prisma 2.26.0:

prisma               : 2.26.0
@prisma/client       : 2.26.0
Current platform     : windows
Query Engine         : query-engine 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine     : migration-engine-cli 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary        : prisma-fmt 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 9b816b3aa13cc270074f172f30d6eda8a8ce867d
Studio               : 0.408.0

Prisma 3.10.0:

prisma                  : 3.10.0
@prisma/client          : 3.10.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : 73e60b76d394f8d37d8ebd1f8918c79029f0db86
Studio                  : 0.458.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (9 by maintainers)

Most upvoted comments

@millsp It worked! I installed @prisma/client@dev and prisma@dev

Screenshot: image

Output of npx prisma-v: image

Thank you so much to everyone involved in this issue!

The fix will be out in tomorrow’s release, I am therefore closing this issue. Thanks!

Of course! I’ll have an update on this soon

It failed the generate in both the versions I tried (2.27.0 and 3.10.0). But on both the schema was succesfully generated

Hi Jan, we ran a few tests with the same schema we shared with you. We added another model called “dummy” and ran prisma generate on it (spoilers, it failed). But then we made a simple script with javascript to do a findMany and a create on that new table. We could see that the new interface was added to the client and Typescript autocompleted accordingly too. The script ran successfully on every combination of versions we reported at the beggining (prisma versions 2.27.0 and 3.10.10 with node 14 and 16). Here is an image of the executed script with prisma version 2.27.0 and node 16 (it had the same output with every combination): prisma 2 27 0-node16

If we can help with something else, please let me know. We are also looking forward for the fix.

Please tell me when you consider this issue as closed.

Thank you so much!

Hi Jan, great news, we will check this out in a few days to confirm. Thank you so much for your help!

Thanks for the quick turnaround Jan, I’ll run some tests and get back to you.

@janpio I’ve sent you an email with the NDA.

Our team seems to also be getting the same error when running prisma generate .

I just spent a bit of time trying to pinpoint the exact point of failure and I can get it to happen 2 ways:

  • By attaching an additional relation to one of our tables that has a large amount of them (the model is almost 500 lines and the schema is 5.2k lines / 406439 chars)
    • This is our “contacts” table and we link it to most entities in our system to know who created/updated an entity
  • By being in the same state as above (minus the relation that causes a failure) and adding 2 extra models up until I can no longer add anymore models; then adding a few more columns. (this one is 407595 chars)

Reproduction steps:

  • Update DB schema in PSQL into one of the states outline above
  • Run prisma db pull
  • Run prisma generate
    • Error happens here

Error I get in both cases: image

Note: We are using Prisma / Prisma client ^3.12.0

I can provide you a dump of our dev DB & a working/failing schema example if you sign an NDA like above.

As to update the status of this issue, the NDA has been signed and the schema has been shared

Yes, that I am very bad with email obviously. Sorry, fixed and signed from our side.

Hi Jan, I’ve been trying to contact you via email about the NDA, do you have any updates on this?

Awesome Jan, I’m sending you an email right now. Thank you

Hi Janpio, thank you for the quick response, yes it’s correct the project worked before, we had to add new tables due to a use case requirement. It was not a big change, it was two models with few relations. We had the same problem before but the workaround was shortening the relation’s names in some models. We can send you a NDA before sharing the schema but we will need some information, can we continue via email?