Zod prototype mismatch

CCory4/17/2023
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?
Bbloberenober4/17/2023
drizzle-orm doesn't use Zod at all
Bbloberenober4/17/2023
only drizzle-zod does
Bbloberenober4/17/2023
one thing that might cause it is a monorepo setup, where you might potentially have different Zod installations in different packages
CCory4/17/2023
I don't have a monorepo
CCory4/17/2023
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?
Bbloberenober4/17/2023
Honestly, I'm not sure. All I know is drizzle-zod uses Zod as peer dependency, so maybe the issue is with another library.
Bbloberenober4/17/2023
Which library is that, btw?
CCory4/17/2023
Superforms
CCory4/17/2023
They check whether it's a zod object via instanceof
Bbloberenober4/17/2023
which one? 🤔
CCory4/17/2023
https://github.com/ciscoheat/sveltekit-superforms

I see they have, zod": "3.x" where as drizzle-zod uses "zod": "*"
CCory4/17/2023
So that could be the issue
Bbloberenober4/17/2023
Well, * just means "any version"
CCory4/17/2023
Yea I am not an expert I just asked chat GPT lol
Bbloberenober4/17/2023
did you install Zod manually?
Bbloberenober4/17/2023
also, which package manager are you using?
CCory4/17/2023
Yes.
CCory4/17/2023
I am using pnpm
Bbloberenober4/17/2023
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 require('zod') reference in one of the js files
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
Bbloberenober4/17/2023
there may be an easier option to check that (via pnpm cli, probably), but I'm not aware of it 😅
CCory4/17/2023
ok i'll check!
CCory4/17/2023
It they are both using, zod@3.21.4
CCory4/17/2023
double checking though
CCory4/17/2023
Not sure if this matters
CCory4/17/2023
but some comments, I assume auto generated, in index.js in drizzle-kit reference zod@3.20.6
CCory4/17/2023
Seems like they are using same version
CCory4/17/2023
Yea not sure
Bbloberenober4/17/2023
drizzle-kit doesn't matter, its runtime is separate
CCory4/17/2023
ah okay
CCory4/17/2023
well yea it appears they are resolving to same locaiton
CCory4/17/2023
node_modules/.pnpm/zod@3.21.4/node_modules/zod/index
CCory4/17/2023
for both
Bbloberenober4/17/2023
does it work without superforms? if you do the instanceof check yourself?
Bbloberenober4/17/2023
also, does superforms work without drizzle-zod?
CCory4/17/2023
let me check
CCory4/17/2023
No it's false
CCory4/17/2023
so it's nothing to do with superforms
CCory4/17/2023
console.log(schema instanceof ZodObject)
CCory4/17/2023
If you check that with a schema created by drizzle-zod it will return false
CCory4/17/2023
so it appears it's nothing to do with superforms
Bbloberenober4/17/2023
weird
Bbloberenober4/17/2023
all I'm doing is literally returning z.object()
Bbloberenober4/17/2023
can you try reinstalling node_modules?
CCory4/17/2023
sure
CCory4/17/2023
Same thing
Bbloberenober4/17/2023
and just to be sure - if you create z.object() yourself, the instanceof check works?
CCory4/17/2023
uh let me check lol
CCory4/17/2023
correct
CCory4/17/2023
Here is one difference I notice
CCory4/17/2023
If I created a zod object
CCory4/17/2023
and hover
CCory4/17/2023
const exampleZod: ZodObject<{
    name: z.ZodString;
}, "strip", z.ZodTypeAny, {
    name: string;
}, {
    name: string;
}>
CCory4/17/2023
I get this
CCory4/17/2023
: ZodObject<{
CCory4/17/2023
Where as if I hover over drizzle-zod created zodobject
CCory4/17/2023
I get
CCory4/17/2023
(alias) const selectMenuSchema: z.ZodObject<{
    name: z.ZodString;
}, z.UnknownKeysParam, z.ZodTypeAny, {
    ...;
}, {
CCory4/17/2023
notice, : ZodObject<{ vs : z.ZodObject<{
Bbloberenober4/17/2023
that's because you imported z yourself
CCory4/17/2023
ah okay
Bbloberenober4/17/2023
another thing
could you verify you use latest versions of drizzle-orm and drizzle-zod?
Bbloberenober4/17/2023
try running pnpm up -i --latest and see if either of them shows up
CCory4/17/2023
sure
CCory4/17/2023
orm and kit do
CCory4/17/2023
I updated, same error
Bbloberenober4/17/2023
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.
CCory4/17/2023
ok
CCory4/17/2023
Will do
CCory4/17/2023
done!
CCory4/18/2023
Not sure if this helps?