drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: Drizzle-Zod is not compatible with Zod 3.24.x

Open itizarsa opened this issue 1 year ago • 15 comments

Report hasn't been filed before.

  • [x] I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.40.0

What version of drizzle-kit are you using?

0.30.5

Other packages

drizzle-zod@^0.7.0

Describe the Bug

After updating to Zod v3.24.0, which implements @standard-schema/spec, I am encountering an error when using createSelectSchema or createInsertSchema on z.infer. Below is the error message

is missing the following properties from type 'ZodType<any, any, any>': "~standard", "~validate"
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
import { User } from "../database/schema/user.ts";

export const SelectUser = createSelectSchema(User);

export type TSelectUser = z.infer<typeof SelectUser>;

itizarsa avatar Mar 10 '25 07:03 itizarsa

First time using drizzle, I'm having the same issue with all the create functions from drizzle-zod. Below are 2 examples.

Image

Image

KyleJune avatar Apr 02 '25 03:04 KyleJune

I think the issue is actually compatibility with the latest versions of drizzle-orm. I was able to get rid of the errors by downgrading to drizzle-orm version 0.36.0. I got the idea of trying that version because the drizzle-zod package.json had "drizzle-orm": ">=0.36.0", for the peer dependency. I tried drizzle-orm 0.37.0 and above and got the same errors, so it seems to be that drizzle-zod only works with drizzle-orm 0.36.0 currently.

KyleJune avatar Apr 02 '25 03:04 KyleJune

Never mind my last 2 comments. I now think it was an issue with Deno's node compatibility. I was able to get it working with drizzle-orm 0.41.0 after deleting deno.lock and node_modules. Not sure why that fixed my issue. Maybe it was a problem with their handling of peer dependencies.

KyleJune avatar Apr 02 '25 03:04 KyleJune

hi @itizarsa were you able to fix this issue? i still face it on latest drizzle orm and zod

darahask avatar May 25 '25 16:05 darahask

@darahask No

itizarsa avatar May 26 '25 00:05 itizarsa

@itizarsa how you guys are solving this? creating zod schemas manually?

darahask avatar May 26 '25 05:05 darahask

@darahask Unfortunately yes

itizarsa avatar May 26 '25 14:05 itizarsa

Big importance bug!

elieven avatar May 27 '25 02:05 elieven

It is a big issue, and a comment from the maintainers would be great on this. I believe this issue comes from a TypeScript types mismatch. The creator functions return a type of BuildSchema, while everything Zod-related wants a type of ZodObject.

devbucket avatar May 28 '25 08:05 devbucket

Hello @devbucket @elieven
I had a similar issue with [email protected] and [email protected] [email protected]. issue

Why don't you upgrade to the latest versions and try [email protected]? If you do, make sure to do import { z } from 'zod/v4';

Hope that helps

sevspo avatar May 28 '25 12:05 sevspo

@sevspo That works perfectly! Thanks for the advice!

devbucket avatar May 28 '25 15:05 devbucket

If you're still using Zod v3, stick with [email protected].

To use Zod v4, upgrade to [email protected].

See the v0.8.0 changelog for details.

bennobuilder avatar May 31 '25 14:05 bennobuilder

The error is still present

"drizzle-orm": "0.44.1", "drizzle-zod": "0.8.2", "zod": "^3.25.49",

pomazanbohdan avatar Jun 03 '25 20:06 pomazanbohdan

@pomazanbohdan Could you send an example of code that doesn't work with the dependency versions you listed? The initial issue might be solved and you may have encountered a different issue, so I need to see what kind of error you're getting with what code.

L-Mario564 avatar Jun 04 '25 16:06 L-Mario564

My error fix after update package zod https://github.com/drizzle-team/drizzle-orm/issues/4604

pomazanbohdan avatar Jun 05 '25 03:06 pomazanbohdan