DT
Join ServerDrizzle Team
help
Zod prototype mismatch
Even though the Zod object constructor name created by Drizzle is ZodObject, it is not an instanceof ZodObject. This is causing an error in another library I am using that accepts ZOD objects.
Since I've got Zod as a peer dependency, it should be expected that drizzle-zod is using that version when it creates a Zod objects? I could be off here.
It appears that drizzle-zod has ZOD as a peer dependecy, but drizzle-orm does not?
Since I've got Zod as a peer dependency, it should be expected that drizzle-zod is using that version when it creates a Zod objects? I could be off here.
It appears that drizzle-zod has ZOD as a peer dependecy, but drizzle-orm does not?
drizzle-orm doesn't use Zod at all
only drizzle-zod does
one thing that might cause it is a monorepo setup, where you might potentially have different Zod installations in different packages
I don't have a monorepo
Is this something that you guys can fix on your end? Or something I can tell to the package maintainer of the library I am using?
Honestly, I'm not sure. All I know is drizzle-zod uses Zod as peer dependency, so maybe the issue is with another library.
Which library is that, btw?
Superforms
They check whether it's a zod object via
instanceof
which one? 🤔
https://github.com/ciscoheat/sveltekit-superforms
I see they have,
I see they have,
zod": "3.x"
where as drizzle-zod uses "zod": "*"
So that could be the issue
Well,
*
just means "any version"Yea I am not an expert I just asked chat GPT lol
did you install Zod manually?
also, which package manager are you using?
Yes.
I am using pnpm
you can shed more light into the issue by checking which Zod versions do both drizzle-zod and superforms reference
you can do that by trying to open the library contents inside node_modules and following the
once you do, pay attention to the resolved zod file path, as it will contain the resolved Zod version
if those references from drizzle-zod and superforms resolve to different paths, that means those libs use different zod instances, hence the error
you can do that by trying to open the library contents inside node_modules and following the
require('zod')
reference in one of the js filesonce you do, pay attention to the resolved zod file path, as it will contain the resolved Zod version
if those references from drizzle-zod and superforms resolve to different paths, that means those libs use different zod instances, hence the error
there may be an easier option to check that (via pnpm cli, probably), but I'm not aware of it 😅
ok i'll check!
It they are both using,
zod@3.21.4
double checking though
Not sure if this matters
but some comments, I assume auto generated, in index.js in drizzle-kit reference
zod@3.20.6
Seems like they are using same version
Yea not sure
drizzle-kit doesn't matter, its runtime is separate
ah okay
well yea it appears they are resolving to same locaiton
node_modules/.pnpm/zod@3.21.4/node_modules/zod/index
for both
does it work without superforms? if you do the instanceof check yourself?
also, does superforms work without drizzle-zod?
let me check
No it's false
so it's nothing to do with superforms
console.log(schema instanceof ZodObject)
If you check that with a schema created by drizzle-zod it will return false
so it appears it's nothing to do with superforms
weird
all I'm doing is literally returning z.object()
can you try reinstalling node_modules?
sure
Same thing
and just to be sure - if you create z.object() yourself, the instanceof check works?
uh let me check lol
correct
Here is one difference I notice
If I created a zod object
and hover
const exampleZod: ZodObject<{
name: z.ZodString;
}, "strip", z.ZodTypeAny, {
name: string;
}, {
name: string;
}>
I get this
: ZodObject<{
Where as if I hover over drizzle-zod created zodobject
I get
(alias) const selectMenuSchema: z.ZodObject<{
name: z.ZodString;
}, z.UnknownKeysParam, z.ZodTypeAny, {
...;
}, {
notice,
: ZodObject<{
vs : z.ZodObject<{
that's because you imported
z
yourselfah okay
another thing
could you verify you use latest versions of drizzle-orm and drizzle-zod?
could you verify you use latest versions of drizzle-orm and drizzle-zod?
try running
pnpm up -i --latest
and see if either of them shows upsure
orm and kit do
I updated, same error
Well, I'm out of ideas for now. The instanceof check works in a test inside drizzle-zod, but that's expected, since it always uses the same Zod version as the drizzle-zod itself. If you can create a reproduction repo, it might help to resolve this.
ok
Will do
done!
Not sure if this helps?