-
-
Notifications
You must be signed in to change notification settings - Fork 204
Description
Version Number
5.2.2
Codesandbox/Expo snack
N/A - Monorepo-specific issue with pnpm workspaces
Steps to reproduce
- Set up a pnpm workspace with multiple apps using different Zod versions
- Install @hookform/[email protected] in App A with Zod 4.x
- Install @hookform/[email protected] in App B with Zod 3.x
- Use pnpm overrides to enforce specific Zod versions per app
- Run TypeScript typecheck
- Observe TypeScript errors about incompatible Zod types even though runtime dependency resolution is correct
Expected behaviour
@hookform/[email protected] should declare zod as an optional peer dependency in package.json, similar to how other validation libraries are declared (yup, joi, etc.).
This would allow package managers like pnpm to properly symlink the correct Zod version into @hookform/resolvers' node_modules, ensuring TypeScript can resolve to the correct type definitions.
Expected package.json to include:
"peerDependencies": {
"react-hook-form": "^7.55.0",
"zod": "*"
},
"peerDependenciesMeta": {
"zod": {
"optional": true
}
}Actual behaviour (what went wrong):
@hookform/[email protected] does not declare zod as a peer dependency. While it uses @standard-schema/utils to provide validation, TypeScript still needs to resolve Zod types when using zodResolver.
In a pnpm workspace with multiple Zod versions:
- pnpm doesn't create a Zod symlink in @hookform/resolvers' node_modules
- TypeScript walks up the directory tree to find Zod types
- TypeScript finds the wrong Zod version (e.g., finds Zod 3.x when it should use Zod 4.x)
- This causes type errors like:
Type 'import(".../[email protected]/...")' is not assignable to type 'import(".../[email protected]/...")'
Workaround:
Had to manually add peer dependency using pnpm's packageExtensions:
"pnpm": {
"packageExtensions": {
"@hookform/[email protected]": {
"peerDependencies": {
"zod": "*"
}
}
}
}What browsers are you seeing the problem on?
No response
Relevant log output
Code of Conduct
- I agree to follow this project's Code of Conduct