Skip to content

issue: Peer dependencies not picked up by package managers #762

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
1 task done
arlyon opened this issue Apr 8, 2025 · 5 comments · May be fixed by #765
Open
1 task done

issue: Peer dependencies not picked up by package managers #762

arlyon opened this issue Apr 8, 2025 · 5 comments · May be fixed by #765

Comments

@arlyon
Copy link

arlyon commented Apr 8, 2025

Version Number

5.0.1

Codesandbox/Expo snack

https://codesandbox.io/p/devbox/hkjpmt

Steps to reproduce

  • open codesandbox vm
  • cd apps/site
  • pnpm ls --depth 2 --prod

Observe

@hookform/resolvers 5.0.1
├── @standard-schema/utils 0.3.0
└─┬ react-hook-form 7.55.0 peer
  └── react 19.0.0 peer

Expected behaviour

For the resolvers to build reliably, the package manager needs to know what the peer deps are so that they may link them properly. Without this information, you can end up with unpredictable build errors where, by pure coincidence, a package (which is not listed in the dependencies such as effect) is not available. I am running into this error but cannot replicate it on codesandbox since the preconditions are dependent on a complicated combination of the layout of your workspace, hoisting, package manager, and indeed the build tool you are using (in my case it is nextjs + turbopack).

Listing peer dependencies only in the package.json files in the sub-folder (effect in this case) does not supply enough information to the package manager to be able to hoist / link reliably. They need to be at the top level.

The only solution is to break this into individually-adressable packages (@hookform/resolver-effect for example) or to list all the peer deps in the top level package.

What browsers are you seeing the problem on?

No response

Relevant log output

➜  site git:(main) ✗ pnpm ls --depth=2 --prod
Legend: production dependency, optional only, dev only

[email protected] /project/workspace/apps/site (PRIVATE)

dependencies:
@hookform/resolvers 5.0.1
├── @standard-schema/utils 0.3.0
└─┬ react-hook-form 7.55.0 peer
  └── react 19.0.0 peer
effect 3.14.6
├── @standard-schema/spec 1.0.0
└─┬ fast-check 3.23.2
  └── pure-rand 6.1.0
effect-example link:../../packages/effect
└─┬ effect 3.14.6
  ├── @standard-schema/spec 1.0.0
  └── fast-check 3.23.2
react 19.0.0
react-dom 19.0.0
├── react 19.0.0 peer
└── scheduler 0.25.0
react-hook-form 7.55.0
└── react 19.0.0 peer

Code of Conduct

  • I agree to follow this project's Code of Conduct
@arlyon
Copy link
Author

arlyon commented Apr 8, 2025

This issue is related: #747

The underlying problem is that, similar to my issue, @standard-schema/utils was not actually declared in the dependencies for this package anywhere so the user's package manager / build tool left it out. The solution to this was to make it a mandatory dependency for all users of @hookform/resolvers but this issue will continue to appear in various forms until every peer dependency in all sub-packages end up in the list of dependencies at the top level.

As mentioned above, the two possible solutions are to publish the sub-packages independently or add all the peer deps from all sub-packages (including @standard-schema/utils) to the peer deps list at the top level.

@arlyon
Copy link
Author

arlyon commented Apr 8, 2025

Solution for now is to use effect via the standardSchemaResolver + Schema.standardSchemaV1 which, thanks to #747, has some of its dependencies listed correctly.

Happy to open a PR to add the peer-deps at the top level, if that is something you are interested in! :)

@jorisre
Copy link
Member

jorisre commented Apr 8, 2025

Hey @arlyon , thanks for flagging this! We're happy to take a look or chat about your PR for adding the peer deps at the top level.

@arlyon arlyon linked a pull request Apr 9, 2025 that will close this issue
@fpapado
Copy link

fpapado commented Apr 25, 2025

Heya! We've also run into this issue, especially in the context of a large (pnpm) monorepo, whereby projects might declare different versions of each underlying validation library. By declaring the peers in @hookform/resolvers, the package manager ensures that only the relevant project version of a given validation library is used, instead of one from another project.

One addition to @arlyon's suggestion (many thanks for opening this issue 🙇), would be to declare peerDependenciesMeta.*.optional true (npm docs, pnpm docs, yarn docs) for each validation library, in addition to declaring it in peerDependencies. This keeps the peer dependency relationship, without bloating the installation size. It would be up to users to install the validation library that they use, which matches the current status quo.

@arlyon
Copy link
Author

arlyon commented Apr 25, 2025

Let me see if I can adjust the PR accordingly

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 a pull request may close this issue.

3 participants