Skip to content
Source
Sign inSign up
TanStack/query

Unmet peer dependencies error with @tanstack/query-persist-client-core #4885

Closedadriencohen(GitHub profile, opens in a new tab) opened this issue 3 comments

Describe the bug

Hello,

Installing @tanstack/query-persist-client-core, @tanstack/query-sync-storage-persister and @tanstack/query-async-storage-persister is leading to unmet peer dependencies errors using Yarn v3:

➤ YN0002: │ @tanstack/query-async-storage-persister@npm:4.22.4 doesn't provide @tanstack/query-core (p61c1a), requested by @tanstack/query-persist-client-core
➤ YN0002: │ @tanstack/query-sync-storage-persister@npm:4.22.4 doesn't provide @tanstack/query-core (pbe790), requested by @tanstack/query-persist-client-core
➤ YN0002: │ @tanstack/react-query-persist-client@npm:4.23.0 [57297] doesn't provide @tanstack/query-core (pd24d6), requested by @tanstack/query-persist-client-core

This is caused by @tanstack/query-persist-client-core requesting @tanstack/query-core as a peer dependencies which is not provided in the previously mentioned packages either as a dependency or passing it down as a peerDependency

My first thought would be to set @tanstack/query-core as a dependency of @tanstack/query-persist-client-core but I'm not sure this is the strategy you want to follow

Your minimal, reproducible example

https://stackblitz.com/edit/node-yjkne1?file=pnpm-lock.yaml

Steps to reproduce

  1. Run pnpm i or yarn install in console

Expected behavior

No unmet peer dependencies warnings or errors should be displayed

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: MacOs
  • Yarn Version: 3.3.1

TanStack Query version

4.23.0

TypeScript version

No response

Additional context

No response

  1. TkDodo added labelsbug

  2. TkDodo added labelspackage: react-query-persist-client

  3. TkDodo removed labelspackage: react-query-persist-client

  4. TkDodo added labelspackage: query-persist-client-core

  5. I've seen this as well. The problem is that persist-query-client-core has a peerDependency on query-core, but no one actually installs query-core - because the framework adapters ship with the query-core built-in, e.g. react:

    https://github.com/TanStack/query/blob/f715b305dedca12ac22812145fa29e42dbd6dfa1/packages/react-query/src/index.ts#L6-L7

    My first thought would be to set @tanstack/query-core as a dependency of @tanstack/query-persist-client-core but I'm not sure this is the strategy you want to follow

    If we add it as a dependency instead of a peerDependency, wouldn't this mean that it would be shipped as a copy with the plugin?. Note that all framework adapters have a dependency on the query-core, so they bring the core with them. I would want to avoid the core being there twice 🤔 . Seems like I don't really understand what it means to have a dependency on something 😅 .

    But it works at runtime as it is right now, if you have one of the framework adapters, because they bring the core. So maybe what we'd want is an optional peerDependency? What I would like to express is: You need to have either a dependency on the query core, or on one of the framework adapters to make this plugin work. The persisters import directly from the core though:

    https://github.com/TanStack/query/blob/715f0cc1fdb7acac332d829f203777c31a962947/packages/query-persist-client-core/src/persist.ts#L7

    So it only works with a dependency on the react adapter because it has a dependency on the core itself ...

  6. If we add it as a dependency instead of a peerDependency, wouldn't this mean that it would be shipped as a copy with the plugin?

    It used to be a valid issue but package manager have evolved and are more smart about this. This issue is fixed by what is called hoisting which is now implemented by most package managers and then bundlers should do the work to prevent duplicating dependencies in the final build.

    Seems like I don't really understand what it means to have a dependency on something 😅 .

    To be fair the difference between a dependency and a peerDependency is not all that clear for me either. In your case I'm pretty sure there is definitely multiple valid dependency/peerDependency trees to achieve the same result. I believe it comes down to you to choose the "UX" you want about installing your packages.

    What I'm sure of is that:

    • Given a dependency A which has peerDependencies Ap1, Ap2 ..., ApN
    • If you add A to one of your package P as a dependency you have to choose for each ApX between adding it to P's dependencies or peerDependencies
    • If you don't do that you might have bugs because you don't have the correct version of @tanstack/query-core

    A partial list of solutions I have for our issue:

    1. Make @tanstack/query-core a peerDependency of all your packages even @tanstack/react-query so the package.json of a user will look like this:
        "@tanstack/query-core": "^4.23.0",
        "@tanstack/react-query": "^4.23.0",
        "@tanstack/react-query-persist-client": "^4.23.0",

    This would be similar to packages like @envelop or @dnd-kit

    1. You are not using ranges to allow your "plugins" to work with multiple cores so you could also set @tanstack/query-core as a dependency of all packages which need it. The package.json will end up like this:
        "@tanstack/react-query": "^4.23.0",
        "@tanstack/react-query-persist-client": "^4.23.0",

    This what @sentry is doing with its packages @sentry/react where you can add @sentry/tracing

    I hope it makes sense to you now and keep mind I could be wrong on some parts as it's quite a tricky subject.

  7. okay, let's try making it a dependency then. Would you like to contribute this?

  8. TkDodo closed this

Sign in to join this conversation.