Skip to content

No QueryClient set, use QueryClientProvider to set one #9796

@stevenmckinnon

Description

@stevenmckinnon

Describe the bug

Hi,

Apologies in advanced, this is something I'm building at my job so it will be slightly vague but I will do my best to describe it.

I have a library, let's call "Core". Core is an app wrapper that sets up a bunch of basic things for applications, theme provider etc. This includes QueryClientProvider from this library, and exposes some queries for consumers to use. @tanstack/react-query is installed as a peer dependency here.

I have another library that is a reporting tool, it uses these queries in it's components and that all works fine when I'm testing in Storybook. @tanstack/react-query is not installed as a dependency here but Core is pulling it in when installed.

When I try to install both of these libraries into my application, and wrap the whole app with Core, I get the error No QueryClient set, use QueryClientProvider to set one

Technical details:

Using Vite as build tool with vite-plugin-externalize-deps to externalize peer dependencies
Core library structure: App → Core (provides QueryClientProvider) → ReportingLibrary (uses useQuery hooks)
The QueryClientProvider is definitely rendered (confirmed with React DevTools)
Error occurs when ReportingLibrary components try to use the hooks
Works in isolation (Storybook) but fails when all libraries are composed together
Using @tanstack/react-query version 5.90.3
Suspected issue: Multiple instances of @tanstack/react-query being loaded despite peer dependency configuration, causing context isolation between the provider and consumers across package boundaries.

What I've tried:

Confirmed @tanstack/react-query is a peer dependency in Core
Added explicit externalization in Vite config
Verified no duplicate installations with npm ls
Exported QueryClient instance from Core library
Has anyone encountered similar issues with library composition and React Query context not crossing package boundaries?

I am using Vite as a build tool.

Your minimal, reproducible example

Not possible

Steps to reproduce

Add and export QueryClientProvider and queries to library A
Build and publish library A
Install to library B and consume queries
Build and publish library B
Install both library A and B to application
Wrap application in QueryClientProvider from library A

Expected behavior

Queries should find the QueryClientProvider wrapping the application

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Windows

Tanstack Query adapter

None

TanStack Query version

5.90.3

TypeScript version

5.2.2

Additional context

No response

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