zod icon indicating copy to clipboard operation
zod copied to clipboard

Cannot find module 'zod/v4' or its corresponding type declarations.

Open RossMcMillan92 opened this issue 7 months ago • 4 comments

I have seen the solution is to update the module and moduleResolution entries in the tsconfig. However, this isn't ideal as it breaks other things in our projects.

This is particularly frustrating as we had already done a lot of work to migrate to zod4 when it was on the "next" branch. But now that it's been officially released, we have to keep using v3 but with the "zod/v4" import, which breaks types.

Can we just have a 4.0.0 release? Would remove the requirement to change tsconfig.json, making migration so much easier.

RossMcMillan92 avatar May 22 '25 11:05 RossMcMillan92

We are also having issues with the build. Initially using the v3.25.7 we had the same errors trying to use zod/v4. Now I updated to v3.25.20 and our vite build will not compile. I will investigate and see if we can get some more information but theres defintely something problematic with the /v4 and typescript that is no longer working. (It was working with the ...beta... version)

rfsmart-psimoneau avatar May 22 '25 13:05 rfsmart-psimoneau

TS2307: Cannot find module zod/v4 or its corresponding type declarations.

We cannot change our module/moduleResolutions either. I guess we're stuck on the 4.0.0 beta.

stevensacks avatar May 22 '25 16:05 stevensacks

I think a valid solution is the following addition to your tsconfig file:

"paths": {
      /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
      "zod/v4": ["./node_modules/zod/dist/types/v4/index.d.ts"],
      "zod/v4/core": ["./node_modules/zod/dist/types/v4/core/index.d.ts"]
    },

Note: One might not need the v4/core path. I just pasted it from my setup since I needed it.

That way the module resolution is not changed and everything works as it is supposed to.

AGalabov avatar May 23 '25 12:05 AGalabov

Unfortunately, that doesn't work. Now it throws this error.

✘ [ERROR] Could not resolve "./classic/index.js"

    node_modules/zod/dist/types/v4/index.d.ts:1:15:
      1 │ import z4 from "./classic/index.js";

stevensacks avatar May 27 '25 04:05 stevensacks

~~What tsconfig are expected for this to work? I am encountering this issue and my tsconfig seems to be as per the requirements~~

Updated to latest version and seems to be working

Nikola-Milovic avatar Jun 01 '25 05:06 Nikola-Milovic

I tried it and I no longer get this error 🎉!

But, now there's a new error: https://github.com/colinhacks/zod/issues/4615

stevensacks avatar Jun 04 '25 06:06 stevensacks

still go this with monorepo and install zod in the root with pnpm

hi-reeve avatar Jun 05 '25 07:06 hi-reeve

Long fixed at this point

colinhacks avatar Jun 06 '25 19:06 colinhacks

Still an issue actually

margaretjoanmiller avatar Nov 25 '25 04:11 margaretjoanmiller

still go this with monorepo and install zod in the root with pnpm

This helps ty

itKyryl avatar Dec 12 '25 10:12 itKyryl