client.defaultQueryOption is not a function
Error = Uncaught TypeError: client.defaultQueryOptions is not a function



12 Replies
equal-aqua•3y ago
You're mixing v4 (devtools?) with v5
rival-black•3y ago
I had this error too, no time to create an issue … the problem is due to a bad call of useQuery, not using the object form. When not using TS we (poor devs) do not have feedback. What about throwing a dedicated error for this one?
More precisely we should be able to detect the bad client before
equal-aqua•3y ago
yeah, I think this is just the first thing that errors.
What I would do is add a check in
useQuery that logs a descriptive error if useQuery is called with more than one argument or if the first arg isn't an object, in non-prod builds.
we already have some checks, e.g. here:
https://github.com/TanStack/query/blob/35539bf34f4e623c9ad70bbcd3d01e1f837bfa63/packages/query-core/src/query.ts#L474-L478GitHub
query/packages/query-core/src/query.ts at 35539bf34f4e623c9ad70bbcd...
🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query. - TanStack/query
equal-aqua•3y ago
please contribute this if you want 🙂
rival-black•3y ago
On my side it would be more « if I have time »
From what I encountered this is also true for fetchQuery and other client methods
Will try to have a look, no guarantee on timing though
compatible-crimsonOP•3y ago
I found solution

rival-black•3y ago
Yep starting v5, this is the only supported syntax.
@TkDodo 🔮 I had some times to look after this today. I have 2 ideas to help with this. Would like some feedback about them if you have time.
1- add a check on
options in useBaseQuery to make sure it is an Object. Error if not.
2- add a check on the type of queryClient passed to useQueryClient. This is the culprit in the error above. Due to the change in useQuery signature, the queryOptions are passed as 3rd param of useBaseQuery <=> queryClient. It is then passed to useQueryClient which returns it if defined.
I can submit a PR with the 2 proposals above to discuss.
Thxrival-black•3y ago
1st idea

rival-black•3y ago
2nd idea

equal-aqua•3y ago
1st idea looks good 👍
rival-black•3y ago
Here we go => https://github.com/TanStack/query/pull/6288
GitHub
Better error in dev to identify bad useQuery calls by GLabat · Pull...
Starting v5, useQuery only accepts the Object form argument => https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object.
For projects without TS...
rival-black•3y ago
Available in latest version
Starting v5.7.0