{"record":{"id":"031b2d8ab8e6d05a","repo":"cube-js/cube","slug":"cube-api-client-is-not-provided","errorCode":null,"errorMessage":"Cube API client is not provided","messagePattern":"Cube API client is not provided","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/cubejs-client-react/src/hooks/cube-query.ts","lineNumber":91,"sourceCode":"  const [isLoading, setLoading] = useState(!options.skip);\n  const [resultSet, setResultSet] = useState<ResultSet | null>(null);\n  const [progress, setProgress] = useState<ProgressResponse | null>(null);\n  const [error, setError] = useState<Error | null>(null);\n  const context = useContext(CubeContext);\n\n  let subscribeRequest: UnsubscribeObj | null = null;\n\n  // `progressResponse` is not part of the public `ProgressResult` API\n  const progressCallback: ProgressCallback = (progressResult) => setProgress(\n    (progressResult as unknown as ProgressResultWithResponse).progressResponse\n  );\n\n  async function fetch() {\n    const { resetResultSetOnChange } = options;\n    const cubeApi = options.cubeApi || context?.cubeApi;\n\n    if (!cubeApi) {\n      throw new Error('Cube API client is not provided');\n    }\n\n    if (resetResultSetOnChange) {\n      setResultSet(null);\n    }\n\n    setError(null);\n    setLoading(true);\n\n    try {\n      const response = await cubeApi.load(query, {\n        mutexObj: mutexRef.current,\n        mutexKey: 'query',\n        progressCallback,\n        castNumerics: Boolean(typeof options.castNumerics === 'boolean' ? options.castNumerics : context?.options?.castNumerics),\n        ...(options.cache ? { cache: options.cache } : {}),\n      });\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-client-react/src/hooks/cube-query.ts#L73-L109","documentation":"useCubeQuery's internal fetch() resolves the API client from options.cubeApi or the CubeContext provider. If neither supplies a CubeApi instance, it throws because there is no client to send the query to.","triggerScenarios":"Calling useCubeQuery outside a <CubeProvider> without passing { cubeApi } in options; passing cubeApi: undefined; rendering the hook before context is populated.","commonSituations":"Forgot to wrap the app in <CubeProvider cubeApi={cubeApi(...)}>; using the hook in a component tree that sits above the provider; dynamically rendering a chart component that imports the hook without a client; testing the hook without a wrapper.","solutions":["Wrap the component tree in <CubeProvider cubeApi={cubeApi('token', { apiUrl })}>.","Pass the client directly: useCubeQuery(query, { cubeApi }).","Ensure the hook is used in a child component of CubeProvider, not a sibling/parent.","Fix ordering issues where a context consumer reads context before the provider sets cubeApi."],"exampleFix":"// before\nconst { resultSet } = useCubeQuery(query); // no provider, no cubeApi\n// after\nconst [cubeApi] = useState(() => cube('CUBEJS_TOKEN', { apiUrl: 'http://localhost:4000/cubejs-api/v1' }));\nconst { resultSet } = useCubeQuery(query, { cubeApi });","handlingStrategy":"validation","validationCode":"if (!options.cubeApi && !context?.cubeApi) {\n  throw new Error('useCubeQuery requires a cubeApi via options or CubeProvider');\n}","typeGuard":"function isCubeApi(v: unknown): v is { load: Function; sql: Function } {\n  return !!v && typeof v === 'object' && typeof (v as any).load === 'function';\n}","tryCatchPattern":"try {\n  const { resultSet } = useCubeQuery(query);\n} catch (e) {\n  if (e.message === 'Cube API client is not provided') {\n    console.error('Wrap your app in <CubeProvider cubeApi={...}> or pass options.cubeApi');\n  }\n}","preventionTips":["Wrap the whole component tree in <CubeProvider>.","Pass cubeApi explicitly in options when outside a provider.","Keep @cubejs-client/react and @cubejs-client/core versions aligned.","Write a test that renders the hook without a provider to fail fast in CI."],"tags":["react","hooks","configuration"],"backgroundTag":"missing-client-configuration","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}