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
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,
zod": "3.x"
where as drizzle-zod uses "zod": "*"
So that could be the issueWell,
*
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
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 😅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 suredrizzle-kit doesn't matter, its runtime is separate
ah okay
well yea it appears they are resolving to same locaiton
node_modules/.pnpm/[email protected]/node_modules/zod/index
for bothdoes 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
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
I get this
: ZodObject<{
Where as if I hover over drizzle-zod created zodobject
I get
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?
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!
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) {
...
Not sure if this helps?