drizzle-orm
drizzle-orm copied to clipboard
[BUG]: Variable created by drizzle-zod is not an instanceof ZodObject
What version of drizzle-orm
are you using?
0.24.0 for drizzle-orm, and 0.3.0 for drizzle-zod
What version of drizzle-kit
are you using?
No response
Describe the Bug
When checking whether the object created by drizzle-zod is an instanceof ZodObject, it returns false.
Expected behavior
It should return True.
Environment & setup
I have setup a basic repo for a SvelteKit project with a page to test what I mean.
https://github.com/saturnonearth/drizzle-zod-bug
- Install repo and depencies
-
pnpm run dev --open
- See output in browser
- File where test is being run is
/src/routes/+page.svelte
@dhruvsaxena1998
Probably, in your case it's better to use safeParse
.
I tried to reproduce this in node project without svelte-kit, and this issue has gone.
I tried to reproduce this in node project without svelte-kit, and this issue has gone.
Interesting, so you think it's a SvelteKit bug?
I tried to reproduce this in node project without svelte-kit, and this issue has gone.
Interesting, so you think it's a SvelteKit bug?
Probably. Svelte imports ZodType from node_modules/zod/lib/index.mjs file, but createInsertSchema loads ZodType from node_modules/zod/lib/types.js. Same with ZodError. You can check prototypes with Object.getPrototypeOf()
. There are classes from different files.

Thanks for investigating this @MattMsh! I don't think it's a SvelteKit bug, but rather missing ESM support on drizzle-zod/drizzle-orm side - it seems like your projects run in ESM mode, but Drizzle is currently only built in CJS mode, so it always imports the CJS versions of its dependencies, including Zod. So this issue should be resolved on its own once proper ESM support is implemented for our libraries, which is tracked here: https://github.com/drizzle-team/drizzle-orm/issues/163
@MattMsh I tried to use safeParse
export const insertUserSchema = createInsertSchema(users, {
email: (schema) => schema.email.email(),
});
const { success, data, error } = insertUserSchema.safeParse(body);
Facing weird issues.
@MattMsh I tried to use
safeParse
export const insertUserSchema = createInsertSchema(users, { email: (schema) => schema.email.email(), }); const { success, data, error } = insertUserSchema.safeParse(body);
Facing weird issues.
Before destructurization, you must check success
. Look at documentation
This should now be fixed, because the ESM support was implemented.