question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma generate fails on big schema file

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
RodrigoRomero2308commented, May 9, 2022

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

Screenshot: image

Output of npx prisma-v: image

1reaction
RodrigoRomero2308commented, May 9, 2022

Thank you so much to everyone involved in this issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error message reference - Prisma
Prisma Client throws a PrismaClientRustPanicError exception if the underlying engine crashes and exits with a non-zero exit code. In this case, the Prisma...
Read more >
Prisma schema API (Reference)
Describes which generator to use. This can point to a file that implements a generator or specify a built-in generator directly. output, No,...
Read more >
Migration troubleshooting in development - Prisma
Fixing failed migrations in a development environment · Delete the migration.sql file. · Modify the schema - for example, add a default value...
Read more >
Prisma Client API (Reference)
You must re-generate the Prisma Client each time you add or rename a data source. Datasource names are included in the generated client....
Read more >
How to use Prisma with multiple database schemas
If you have tables with the same name in different database schemas, Prisma shows a validation error pointing out the conflict. To fix...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found