8000 Versioning with subpaths (`"zod/v4"`) to enable incremental migration · Issue #4371 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Versioning with subpaths ("zod/v4") to enable incremental migration #4371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
colinhacks opened this issue May 15, 2025 · 1 comment
Closed

Comments

@colinhacks
Copy link
Owner
colinhacks commented May 15, 2025

This is a writeup of a number of structural changes to the package, with the goal of making it easier for the ecosystem to migrate to Zod 4. TLDR:

  • Zod 4 will not initially be published as zod@4.0.0 on npm.
  • Instead it will be exported at a subpath ("zod/v4") alongside zod@3.25.0). Despite this, Zod 4 is considered stable and production-ready.
  • Zod 3 will continue to be exported from the package root ("zod"). Projects can incrementally migrate as they see fit.
  • The @zod/core package is being dropped in favor of "zod/v4/core"
  • The @zod/mini package is being dropped in favor of "zod/v4-mini"

Sometime later:

  • I'll publish zod@4.0.0 on npm
  • The package root ("zod") will switch over from exporting Zod 3 to Zod 4
  • The "zod/v4" subpath will continue to be available.

Ecosystem libraries are encouraged to build against "zod/v3" and "zod/v4" exclusively as these will remain stable/available across all future versions, including majors.

A more detailed breakdown:


To give the ecosystem time to migrate, Zod 4 will initially be published alongside Zod 3. It will be consumable as a subpath import:

import { z } from "zod/v4";

This approach is analogous to how Golang handles major version changes: https://go.dev/doc/modules/major-version

During this transition window:

  1. Zod 4 is considered 100% stable and production-ready!
  2. The "zod" package will continue to be published in the 3.x.x version range on npm. The /v4 subpath will be added in the zod@3.25.0 release.
  3. Zod 3 will continue to be exported from the package root ("zod") as well as a new subpath ("zod/v3"). It will continue to receive bug fixes & stability improvements.

More generally, the multi-package structure has been abandoned in favor of a "monopackage". The @zod/core and @zod/mini packages are being dropped in favor of zod/v4/core and zod/v4-mini subpaths, respectively.

Why? Zod occupies a unique place in the ecosystem. Many libraries/frameworks in the ecosystem accept user-defined Zod schemas. This means their user-facing API is strongly coupled to Zod and its various classes/interfaces/utilities. For these libraries/frameworks, a breaking change to Zod necessarily causes a breaking change for their users. A Zod 3 ZodType is not assignable to a Zod 4 ZodType.

So why can't libraries just support v3 and v4 simultaneously? Unfortunately the limitations of peerDependencies (and inconsistencies between package managers) make it extremely difficult to elegantly support two major versions of one library simultaneously.

If I naively published zod@4.0.0 to npm, the vast majority of the libraries in Zod's ecosystem would need to publish a new major version to properly support Zod 4. this includes some high-profile libraries like the ai SDK. it would trigger a "version bump avalanche" across the ecosystem and generally create a huge amount of frustration and work.

By co-publishing v3 and v4 together, we solve this problem. it provides a straightforward way to support Zod 3 and Zod 4 (including Zod Mini) simultaneously. they can continue defining a single peerDependency on "zod"; no need for more arcane solutions like npm aliases, optional peer dependencies, or a "zod-compat" package.

Existing projects will be able upgrade Zod to the latest minor version (zod@3.25) to get access to "zod/v4" and its many improvements. (During the beta period, they can use zod@next.) The can do this with confidence that there will be zero breakage.

Libraries will need to bump the minimum version of their "zod" peer dependency to zod@^3.25.0. They can then reference both Zod 3 and Zod 4 in their implementation:

import * as z3 from "zod/v3"
import * as z4 from "zod/v4"

Later, once there's broad support for v4, we'll bump the major version on npm and start exporting Zod 4 from the package root, completing the transition. Zod 3 will remain available at "zod/v3" forever. While it may seem unorthodox, this is the only approach I'm aware of that enables a clean, incremental migration path for both Zod's users and the libraries in the broader ecosystem.

@colinhacks colinhacks pinned this issue May 15, 2025
@colinhacks
Copy link
Owner Author

Implemented in #4364

@colinhacks colinhacks changed the title Switching to subpaths: "zod/v4", "zod/v4/core" (dropping @zod/core), "zod/v4-mini" (dropping @zod/mini) Versioning with subpaths ("zod/v4") to enable incremental migration May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0