Quick Start
1. Install
Requirements
Component | Minimum |
---|---|
Node.js | 18.x |
Prisma | 6.12.0 |
Zod | 4.0.5 |
TypeScript (recommended) | 5.2+ |
- npm
- yarn
- pnpm
npm install prisma-zod-generator zod @prisma/client
yarn add prisma-zod-generator zod @prisma/client
pnpm add prisma-zod-generator zod @prisma/client
2. Add generator to schema.prisma
generator client {
provider = "prisma-client"
}
generator zod {
provider = "prisma-zod-generator"
// optional output = "./prisma/generated" (JSON config can supply if omitted)
// optional config = "./zod-generator.config.json" (relative to schema file)
}
Config Path Resolution
Config file paths (e.g., config = "./my-config.json"
) are resolved relative to the Prisma schema file location, not the project root. If your schema is at prisma/schema.prisma
, then config = "./my-config.json"
will look for the config file at prisma/my-config.json
.
3. (Optional) Create configuration file
Create prisma/zod-generator.config.json
(next to your schema file):
{
"mode": "full",
"pureModels": true,
"variants": {
"pure": { "enabled": true },
"input": { "enabled": true },
"result": { "enabled": true },
},
}
4. Generate
npx prisma generate
5. Consume
import { UserSchema, UserInputSchema } from './prisma/generated/schemas';
UserSchema.parse(data);
Directory Layout (multi-file default)
prisma/generated/
schemas/
enums/
objects/
variants/
index.ts
models/
Single-file mode collapses to schemas.ts
via config (useMultipleFiles:false
).