Prisma CLI Hangs on `npx prisma generate` or any other CLI command When Using Zod Generator
Closed this issue · 1 comments
Title: Prisma CLI Hangs on npx prisma generate
or any other CLI command When Using Zod Generator
Describe the bug
When using the Zod generator in the Prisma schema, the Prisma CLI (npx prisma generate
) hangs after generating the Prisma Client and Zod Prisma Types. The process completes the generation of both Prisma Client and Zod Prisma Types but does not exit as expected, requiring a manual interruption (Control+C) to terminate the process. This issue does not occur when the Zod generator is removed from the schema.
As far as I know, this is happening on Mac.
Package versions (please complete the following information):
- zod: Included as part of "zod-prisma-types" version "^3.1.6"
- prisma: "^5.9.0"
Additional context
The issue seems to be specifically related to the integration of the Zod generator within the Prisma schema. Here's a snippet from the prisma.schema
file highlighting the Zod generator configuration:
generator zod {
provider = "npx zod-prisma-types"
output = "./zod"
useMultipleFiles = true
createRelationValuesTypes = true
createPartialTypes = true
writeNullishInModelTypes = true
createInputTypes = false
writeBarrelFiles = false
useTypeAssertions = true
}
And here's the output from running npx prisma generate
that hangs:
Prisma schema loaded from schema.prisma
✔ Generated Prisma Client (v5.9.0) to ./../../node_modules/@prisma/client in 605ms
✔ Generated Zod Prisma Types to ./zod in 1.92s
Start using Prisma Client in Node.js (See: https://pris.ly/d/client)
(The process hangs here requiring a Control+C to exit.)
This behaviour obstructs workflow automation and continuous integration processes, as the command does not exit successfully on its own. Removing the Zod generator configuration from the Prisma schema resolves the issue, suggesting that the problem lies in the interaction between Prisma CLI and the Zod generator.
I wanted to follow up on this issue and share a critical discovery that resolved the hanging behavior of npx prisma generate
when using the Zod generator.
Upon closer inspection, I realized that the cause of the problem was the use of npx
within the provider
field of the Zod generator configuration in my schema.prisma
. Here's the original configuration that caused the issue:
generator zod {
provider = "npx zod-prisma-types"
...
}
Resolution: The issue was resolved by removing npx
from the provider
value, changing it to simply:
generator zod {
provider = "zod-prisma-types"
...
}
This adjustment made the npx prisma generate
command complete successfully without hanging. It appears that the use of npx
in the provider field is unnecessary and leads to unexpected behavior in the generation process.