DT
Drizzle Team•2y ago
Cory

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?
28 Replies
Dan
Dan•2y ago
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
Cory
CoryOP•2y ago
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?
Dan
Dan•2y ago
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?
Cory
CoryOP•2y ago
Superforms They check whether it's a zod object via instanceof
Dan
Dan•2y ago
which one? 🤔
Cory
CoryOP•2y ago
https://github.com/ciscoheat/sveltekit-superforms I see they have, zod": "3.x" where as drizzle-zod uses "zod": "*" So that could be the issue
Dan
Dan•2y ago
Well, * just means "any version"
Cory
CoryOP•2y ago
Yea I am not an expert I just asked chat GPT lol
Dan
Dan•2y ago
did you install Zod manually? also, which package manager are you using?
Cory
CoryOP•2y ago
Yes. I am using pnpm
Dan
Dan•2y ago
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 there may be an easier option to check that (via pnpm cli, probably), but I'm not aware of it 😅
Cory
CoryOP•2y ago
ok i'll check! It they are both using, [email protected] double checking though Not sure if this matters but some comments, I assume auto generated, in index.js in drizzle-kit reference [email protected] Seems like they are using same version Yea not sure
Dan
Dan•2y ago
drizzle-kit doesn't matter, its runtime is separate
Cory
CoryOP•2y ago
ah okay well yea it appears they are resolving to same locaiton node_modules/.pnpm/[email protected]/node_modules/zod/index for both
Dan
Dan•2y ago
does it work without superforms? if you do the instanceof check yourself? also, does superforms work without drizzle-zod?
Cory
CoryOP•2y ago
let me check No it's false so it's nothing to do with superforms
console.log(schema instanceof ZodObject)
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
Dan
Dan•2y ago
weird all I'm doing is literally returning z.object() can you try reinstalling node_modules?
Cory
CoryOP•2y ago
sure Same thing
Dan
Dan•2y ago
and just to be sure - if you create z.object() yourself, the instanceof check works?
Cory
CoryOP•2y ago
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;
}>
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, {
...;
}, {
(alias) const selectMenuSchema: z.ZodObject<{
name: z.ZodString;
}, z.UnknownKeysParam, z.ZodTypeAny, {
...;
}, {
notice, : ZodObject<{ vs : z.ZodObject<{
Dan
Dan•2y ago
that's because you imported z yourself
Cory
CoryOP•2y ago
ah okay
Dan
Dan•2y ago
another thing 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 up
Cory
CoryOP•2y ago
sure orm and kit do I updated, same error
Dan
Dan•2y ago
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.
Cory
CoryOP•2y ago
ok Will do done!
Cory
CoryOP•2y ago
Stack Overflow
TypeScript instanceof not working
I'm having issues using the instanceof operator and it doesn't seem to work. Here is a part of my code: const results = _.map(items, function(item: Goal|Note|Task, index: number) { ...
Cory
CoryOP•2y ago
Not sure if this helps?
Want results from more Discord servers?
Add your server