Skip to content

Commit f7ad47e

Browse files
authored
fix(examples/nextjs-app): downgrade zod to v3 to fix type-check error (#305)
@hookform/resolvers@5.2.2 has a known type incompatibility with zod v4.x due to branded version mismatch (_zod.version.minor). - Downgrade zod from ^4.4.3 to ^3.24.0 - Update schema to use zod v3 API (z.string().url() instead of z.url(), required_error/invalid_type_error instead of error option) - Update import from 'zod/v4' to 'zod' See: react-hook-form/resolvers#842
1 parent 03867af commit f7ad47e

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

examples/nextjs-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"react": "catalog:",
1717
"react-dom": "catalog:",
1818
"react-hook-form": "^7.71.2",
19-
"zod": "^4.4.3"
19+
"zod": "^3.24.0"
2020
},
2121
"devDependencies": {
2222
"@tailwindcss/postcss": "catalog:",

examples/nextjs-app/src/modules/pages/form-demo.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import * as React from "react";
1919
import { useForm, Controller } from "react-hook-form";
2020
import { zodResolver } from "@hookform/resolvers/zod";
21-
import { z } from "zod/v4";
21+
import { z } from "zod";
2222

2323
type ProfileFormData = {
2424
username: string;
@@ -479,10 +479,13 @@ const contactSchema = z.object({
479479
name: z.string().min(1, "Name is required").max(50, "Name must be 50 characters or less"),
480480
email: z.string().email("Please enter a valid email address"),
481481
age: z
482-
.number({ error: "Age is required" })
482+
.number({
483+
required_error: "Age is required",
484+
invalid_type_error: "Age is required",
485+
})
483486
.min(18, "Must be at least 18")
484487
.max(120, "Must be 120 or less"),
485-
website: z.union([z.url("Please enter a valid URL"), z.literal("")]).optional(),
488+
website: z.union([z.string().url("Please enter a valid URL"), z.literal("")]).optional(),
486489
message: z.string().min(10, "Message must be at least 10 characters"),
487490
});
488491

pnpm-lock.yaml

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)