Skip to content

issue: TypeScript errors with @hookform/resolvers when Zod is not declared as peer dependency #828

@drac94

Description

@drac94

Version Number

5.2.2

Codesandbox/Expo snack

N/A - Monorepo-specific issue with pnpm workspaces

Steps to reproduce

  1. Set up a pnpm workspace with multiple apps using different Zod versions
  2. Install @hookform/[email protected] in App A with Zod 4.x
  3. Install @hookform/[email protected] in App B with Zod 3.x
  4. Use pnpm overrides to enforce specific Zod versions per app
  5. Run TypeScript typecheck
  6. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions