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)

Most upvoted comments

Holy crap! I accidentally solved my issue! I updated my zod from version ^3.24.4 to the latest version ^3.25.7 and it finally started compiling! No changes to my tsconfig.json:

{
  "compilerOptions": {
    "target": "ESNext",
    "jsx": "preserve",
    "jsxImportSource": "solid-js",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "paths": {
      "~/*": ["./src/*"]
    },
    "types": ["vinxi/types/client"],
    "allowJs": true,
    "strict": true,
    "noEmit": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "isolatedModules": true,
    "inlineSourceMap": true
  }
}

Having the same error. Changing moduleResolution and module causing me problems (like setting type: module in 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

import { v4 as z } from 'zod'