{"record":{"id":"c4fa1b3a14722ea5","repo":"TanStack/query","slug":"no-queryclient-found-in-vue-context-use-vueque","errorCode":null,"errorMessage":"No 'queryClient' found in Vue context, use 'VueQueryPlugin' to properly initialize the library.","messagePattern":"No 'queryClient' found in Vue context, use 'VueQueryPlugin' to properly initialize the library\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/vue-query/src/useQueryClient.ts","lineNumber":18,"sourceCode":"import { hasInjectionContext, inject } from 'vue-demi'\n\nimport { getClientKey } from './utils'\nimport type { QueryClient } from './queryClient'\n\nexport function useQueryClient(id = ''): QueryClient {\n  // ensures that `inject()` can be used\n  if (!hasInjectionContext()) {\n    throw new Error(\n      'vue-query hooks can only be used inside setup() function or functions that support injection context.',\n    )\n  }\n\n  const key = getClientKey(id)\n  const queryClient = inject<QueryClient>(key)\n\n  if (!queryClient) {\n    throw new Error(\n      \"No 'queryClient' found in Vue context, use 'VueQueryPlugin' to properly initialize the library.\",\n    )\n  }\n\n  return queryClient\n}\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/TanStack/query/blob/159982c80b844487054155c38ffc760fe4208daf/packages/vue-query/src/useQueryClient.ts#L1-L25","documentation":"Second guard in `useQueryClient`: Vue's `hasInjectionContext()` passed, but `inject(getClientKey(id))` returned undefined. This means the component is inside setup but `VueQueryPlugin.install` never ran for the app (no client provided), or a different `id` was used to install vs. consume.","triggerScenarios":"Using vue-query hooks without registering `VueQueryPlugin` via `app.use(VueQueryPlugin, { queryClient })`; registering the plugin with a custom `id` but consuming with a different `id`; registering the plugin on a different app instance than the one rendering the component.","commonSituations":"Forgetting `app.use(VueQueryPlugin, { queryClient })` in `main.ts`; passing `VueQueryPlugin` without options (it falls back to creating its own client only if configured); multi-app setups where the plugin is registered on app A but the component is in app B; SSR entry missing plugin install.","solutions":["Install the plugin with an explicit client: `app.use(VueQueryPlugin, { queryClient: new QueryClient() })`.","If using a custom `id` in install, pass the same `id` to `useQueryClient(id)`.","Verify only one Vue app instance is in play and the plugin is registered on it.","For SSR, ensure `VueQueryPlugin` is installed in both server and client app creation paths."],"exampleFix":"// before\nconst app = createApp(App)\napp.mount('#app')\n// after\nimport { VueQueryPlugin } from '@tanstack/vue-query'\nimport { QueryClient } from '@tanstack/query-core'\nconst app = createApp(App)\napp.use(VueQueryPlugin, { queryClient: new QueryClient() })\napp.mount('#app')","handlingStrategy":"validation","validationCode":"import { inject, hasInjectionContext } from 'vue-demi'\nimport { getClientKey } from './utils'\nfunction tryFindQueryClient(id = ''): ReturnType<typeof inject> | undefined {\n  if (!hasInjectionContext()) return undefined\n  return inject(getClientKey(id), undefined)\n}","typeGuard":"import { QueryClient } from '@tanstack/query-core'\nconst isQueryClient = (v: unknown): v is QueryClient =>\n  !!v && typeof v.getQueryCache === 'function'","tryCatchPattern":null,"preventionTips":["Install `VueQueryPlugin` with an explicit client: `app.use(VueQueryPlugin, { queryClient })`.","If using a custom `id`, pass the same `id` to `useQueryClient(id)`.","Register the plugin on the same app instance that mounts the components using hooks.","For SSR, install the plugin in both server and client app creation."],"tags":["vue","plugin","queryclient","configuration","injection-context"],"backgroundTag":null,"analyzedSha":"159982c80b844487054155c38ffc760fe4208daf","analyzedAt":"2026-08-12T16:21:52.822Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}