Skip to content

feat(zod-package): support for Zod v4 #5032

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

J-Michalek
Copy link

🔎 Overview

This PR is a basic migration to support Zod v4, there is definitely more work to do, but this could be a little help to get things started. I went ahead and migrated everything I could and all the tests seem to be passing.

I am a little hesitant since I had to install both the beta and the core package of Zod since some types that are needed are only available under the core package now.

Issues affected

closes #5027

Copy link

changeset-bot bot commented Apr 26, 2025

⚠️ No Changeset found

Latest commit: 6922330

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

codecov bot commented Apr 26, 2025

Codecov Report

Attention: Patch coverage is 91.66667% with 15 lines in your changes missing coverage. Please review.

Project coverage is 89.41%. Comparing base (9803aa2) to head (6922330).

Files with missing lines Patch % Lines
packages/zod-next/src/index.ts 91.66% 15 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5032      +/-   ##
==========================================
+ Coverage   89.36%   89.41%   +0.05%     
==========================================
  Files          93       94       +1     
  Lines        8046     8226     +180     
  Branches     1394     1439      +45     
==========================================
+ Hits         7190     7355     +165     
- Misses        849      864      +15     
  Partials        7        7              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@colinhacks
Copy link

Here's a dedicated guide for library authors that answers some common questions: https://v4.zod.dev/library-authors

  1. Best practices around peer dependencies
  2. How to support Zod v3 and Zod v4 simultaneously
  3. How to support Zod & Zod Mini without extra work

Note that the @zod/core package has been abandoned in favor of a subpath: zod/v4/core. This makes it much easier for libraries with build on top of Zod with a single peer dependency on "zod". The reasons for this change are explained in more detail in the beta announcement: https://v4.zod.dev/v4

@J-Michalek
Copy link
Author

J-Michalek commented May 16, 2025

Thanks for your guidelines, I decided that it might be best to go for v3 and v4 simultaneous support for now.

I'm having issues with the following imports:

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

The only import paths I got working is this:

import * as z3 from "zod/src/v3";
import * as z4 from "zod/src/v4/core";

package.json looks like this:

 "peerDependencies": {
    "zod": "^3.25.0"
  },
  "devDependencies": {
    "zod": "next"
  }

Am I doing something wrong?

@logaretm
Copy link
Owner

logaretm commented May 16, 2025

I'm thinking we should instead support standard schemas and not have to deal with specific resolvers for multiple versions of a schema provider.

I've planned this for v5 since standard schemas can be supported without having to implement any resolvers, we would drop support for non-standard schemas tho like yup.

@J-Michalek
Copy link
Author

Yeah that seems like a more reasonable solution.

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

Successfully merging this pull request may close these issues.

Support for Zod 4 (now in beta)
3 participants