Skip to content

Commit 5f83426

Browse files
authored
fix(react-query): export @tanstack/react-query from @ts-rest/react-query/tanstack (#593)
1 parent 3dc697f commit 5f83426

5 files changed

Lines changed: 39 additions & 1 deletion

File tree

.changeset/seven-turtles-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ts-rest/react-query': minor
3+
---
4+
5+
Export the entire `@tanstack/react-query` from `@ts-rest/react-query/tanstack` to fix `No QueryClient set` errors caused by version mismatches

apps/docs/docs/react-query.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,25 @@ Functions that may throw on failure such as `fetchQuery` will throw an error if
296296
Be sure to handle these errors appropriately.
297297

298298
:::
299+
300+
## Troubleshooting
301+
302+
### `No QueryClient set, use QueryClientProvider to set one`
303+
304+
If you see this error despite having set a `QueryClient` using `QueryClientProvider`. Then you might have different versions of `@tanstack/react-query` installed in your project.
305+
306+
This can also happen in rare cases when ESM and CJS versions of the package are mixed by a bundler like Webpack.
307+
308+
If you have made sure that you are using the same version of `@tanstack/react-query` across your project, and are still having problems, you can work around this
309+
by importing `@tanstack/react-query` from `@ts-rest/react-query/tanstack` instead of `@tanstack/react-query`. This will ensure that you are using the same version as the one used
310+
by `@ts-rest/react-query`.
311+
312+
```tsx
313+
import { QueryClient, QueryClientProvider } from '@ts-rest/react-query/tanstack';
314+
315+
const queryClient = new QueryClient()
316+
317+
function App() {
318+
return <QueryClientProvider client={queryClient}>...</QueryClientProvider>
319+
}
320+
```

libs/ts-rest/react-query/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,13 @@
2929
"zod": {
3030
"optional": true
3131
}
32+
},
33+
"typesVersions": {
34+
"*": {
35+
"*": [
36+
"*",
37+
"*.cjs.d.ts"
38+
]
39+
}
3240
}
3341
}

libs/ts-rest/react-query/project.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"compiler": "tsc",
3030
"rollupConfig": "tools/scripts/rollup.config.js",
3131
"generateExportsField": true,
32-
"updateBuildableProjectDepsInPackageJson": true
32+
"additionalEntryPoints": [
33+
"libs/ts-rest/react-query/src/tanstack.ts"
34+
]
3335
}
3436
},
3537
"lint": {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '@tanstack/react-query';

0 commit comments

Comments
 (0)