zod: Cannot find module 'zod/v4' — CommonJS
Similarly to zod, I’m building two versions of one of my libraries: ESM and CommonJS. Until 30 minutes ago, I’ve been having pretty good success with v4, thank you!
I needed this fix, so I decided to upgrade to 3.25.0-beta.20250515T085033, which is using the brand new zod/v4 packaging approach. However, my CommonJS build is now failing with:
src/api/assets/alternates/my/list/schema.ts:1:15 - error TS2307: Cannot find module ‘zod/v4’ or its corresponding type declarations. There are types at ‘/Users/ben/Development/breaka/breaka-platform/breaka-core-js/node_modules/zod/dist/esm/v4/index.d.ts’, but this result could not be resolved under your current ‘moduleResolution’ setting. Consider updating to ‘node16’, ‘nodenext’, or ‘bundler’.
1 import z from ‘zod/v4’;
I can’t change the resolution, since this is a "module": "commonjs" build.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 19 (2 by maintainers)
Holy crap! I accidentally solved my issue! I updated my zod from version
^3.24.4to the latest version^3.25.7and it finally started compiling! No changes to my tsconfig.json:Having the same error. Changing
moduleResolutionandmodulecausing me problems (like settingtype: modulein package.json and other packages like lodash.the previous next version was fine tho.
Is it possible to still publish zod v4 next version ? or maybe
Documented here: https://v4.zod.dev/#requirements