{"record":{"id":"54a67354afa639af","repo":"cube-js/cube","slug":"cannot-create-cubeapi-instance-please-check-that","errorCode":null,"errorMessage":"Cannot create CubeApi instance. Please check that the config is passed correctly and contains all required options.","messagePattern":"Cannot create CubeApi instance\\. Please check that the config is passed correctly and contains all required options\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/cubejs-client-ngx/src/client.ts","lineNumber":42,"sourceCode":"\n  constructor(@Inject('config') private config: any | Observable<any>) {\n    if (this.config instanceof Observable) {\n      this.config.subscribe(() => {\n        this.ready$.next(true);\n      });\n    } else {\n      this.ready$.next(true);\n    }\n  }\n\n  private apiInstance(): CubeApi {\n    if (!this.cubeApi) {\n      if (this.config instanceof Observable) {\n        this.config.subscribe((config) => {\n          this.cubeApi = cube(config.token, config.options);\n\n          if (!this.cubeApi) {\n            throw new Error(\n              'Cannot create CubeApi instance. Please check that the config is passed correctly and contains all required options.'\n            );\n          }\n        });\n      } else {\n        this.cubeApi = cube(this.config.token, this.config.options);\n      }\n    }\n\n    return this.cubeApi;\n  }\n\n  public load(\n    query: Query | Query[],\n    options?: LoadMethodOptions\n  ): Observable<ResultSet<any>> {\n    return from(<Promise<ResultSet<any>>>this.apiInstance().load(query, options));\n  }","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-client-ngx/src/client.ts#L24-L60","documentation":"The Angular client (cubejs-client-ngx) wraps the CubeApi instance behind a proxy class. When a method like load() is called, it lazily instantiates CubeApi via the `cube()` factory using config.token and config.options. If `cube()` returns a falsy value, the client throws this error because without a CubeApi instance no API calls can be made.","triggerScenarios":"Calling load/sql/dryRun/meta/resultSet on CubeClient when `cube(config.token, config.options)` returns null/undefined — typically when the token or options passed to the config are malformed, or a custom/broken `cube` factory is injected via forRoot that returns nothing.","commonSituations":"Forgetting to call CubeClientModule.forRoot(...) with a valid token/apiUrl; passing a config object resolved from an Observable that yields an object missing `token`; injecting a stubbed cube factory in tests that returns undefined; using an outdated config shape where options/token keys were renamed.","solutions":["Ensure CubeClientModule.forRoot is called with { token, apiUrl } (or an Observable of that config) before injecting CubeClient.","Verify the resolved config object has a non-empty `token` string and a valid `options` object.","Check the `cube` factory injected via forRoot (custom DI) actually returns a CubeApi instance.","Upgrade @cubejs-client/ngx and @cubejs-client/core to matching versions so the `cube` factory signature matches."],"exampleFix":"// before\nCubeClientModule.forRoot(null) // or missing forRoot\n// after\nCubeClientModule.forRoot({ token: 'CUBEJS_TOKEN', apiUrl: 'http://localhost:4000/cubejs-api/v1' })","handlingStrategy":"validation","validationCode":"// before injecting / rendering\nconst cfg = { token: 'CUBEJS_TOKEN', apiUrl: 'http://localhost:4000/cubejs-api/v1' };\nif (!cfg.token || !cfg.apiUrl) throw new Error('CubeClient config requires token and apiUrl');\nCubeClientModule.forRoot(cfg);","typeGuard":"function hasCubeConfig(c: unknown): c is { token: string; options?: object } {\n  return !!c && typeof c === 'object' && typeof (c as any).token === 'string' && (c as any).token.length > 0;\n}","tryCatchPattern":"try {\n  await client.load(query);\n} catch (e) {\n  if (e.message.includes('Cannot create CubeApi instance')) {\n    console.error('CubeClient misconfigured: provide token/apiUrl via CubeClientModule.forRoot');\n  }\n  throw e;\n}","preventionTips":["Always call CubeClientModule.forRoot with token and apiUrl before using CubeClient.","When using an Observable config, emit a complete config object.","Keep @cubejs-client/ngx and @cubejs-client/core versions in lockstep.","Add an app-startup assertion that the client config resolves."],"tags":["angular","configuration","initialization"],"backgroundTag":"missing-client-configuration","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}