{"record":{"id":"37e4364cfdd9795e","repo":"cube-js/cube","slug":"either-cubejs-db-type-or-createoptions-driverfacto","errorCode":null,"errorMessage":"Either CUBEJS_DB_TYPE or CreateOptions.driverFactory must be specified","messagePattern":"Either CUBEJS_DB_TYPE or CreateOptions\\.driverFactory must be specified","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-server-core/src/core/OptsHandler.ts","lineNumber":83,"sourceCode":"      throw new Error(\n        'CreateOptions.dbType was removed in v1.7.0. ' +\n        'Use driverFactory instead (return a DriverConfig `{ type, ... }`), ' +\n        'or set the CUBEJS_DB_TYPE environment variable. ' +\n        'See https://github.com/cube-js/cube/blob/master/DEPRECATION.md#dbtype'\n      );\n    }\n\n    const validated = validateOptions(opts);\n\n    // Probed for its throw: the only consumer is per-request code (normalizeQuery)\n    getEnv('defaultTimezone');\n\n    if (\n      !this.isDevMode() &&\n      !process.env.CUBEJS_DB_TYPE &&\n      !opts.driverFactory\n    ) {\n      throw new Error(\n        'Either CUBEJS_DB_TYPE or CreateOptions.driverFactory must be specified'\n      );\n    }\n\n    return validated;\n  }\n\n  /**\n   * Assert value returned from the driver factory.\n   */\n  private assertDriverFactoryResult(\n    val: DriverConfig | BaseDriver,\n  ) {\n    if (isDriver(val)) {\n      if (!this.driverFactoryType) {\n        this.driverFactoryType = 'BaseDriver';\n      } else if (this.driverFactoryType !== 'BaseDriver') {\n        throw new Error(","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-server-core/src/core/OptsHandler.ts#L65-L101","documentation":"sanitizeOptions requires the database type to be discoverable in production mode: either the CUBEJS_DB_TYPE environment variable is set or a CreateOptions.driverFactory is provided. If neither is present (and dev mode is off), startup fails because Cube cannot determine which driver to instantiate. In dev mode this check is skipped because the Playground can supply the type later.","triggerScenarios":"Running cubejs-server-core with CUBEJS_DEV_MODE unset/false, no CUBEJS_DB_TYPE in the environment, and no driverFactory passed to create(). E.g. deploying to production with only CUBEJS_DB_HOST/CUBEJS_DB_NAME set.","commonSituations":"Production deploys where .env wasn't copied; docker images missing CUBEJS_DB_TYPE; code that worked in dev mode (where the check is skipped) failing in prod; multi-data-source setups forgetting CUBEJS_DS_<ds>_DB_TYPE for the default source.","solutions":["Set CUBEJS_DB_TYPE in the environment (e.g. postgres, mysql)","Or pass driverFactory to create(): driverFactory: async () => ({ type: 'postgres', ... })","Verify the env file is actually loaded in the deployment environment","In dev mode, pick the db type in the Playground so it gets persisted"],"exampleFix":"// before\ncreate({ apiSecret: 'secret' }) // prod, no env\n// after\ncreate({ apiSecret: 'secret', driverFactory: async () => ({ type: 'postgres' }) })\n// or: CUBEJS_DB_TYPE=postgres in the environment","handlingStrategy":"validation","validationCode":"function assertDbTypeConfigured(opts) {\n  const devMode = process.env.CUBEJS_DEV_MODE === 'true';\n  if (!devMode && !process.env.CUBEJS_DB_TYPE && typeof opts.driverFactory !== 'function') {\n    throw new Error('Set CUBEJS_DB_TYPE or provide CreateOptions.driverFactory before starting Cube in production');\n  }\n}\nassertDbTypeConfigured(myCreateOptions);","typeGuard":"function hasDbTypeSource(opts) {\n  return typeof opts.driverFactory === 'function' || !!process.env.CUBEJS_DB_TYPE;\n}","tryCatchPattern":"try {\n  const server = await create(opts);\n} catch (e) {\n  if (e.message.includes('Either CUBEJS_DB_TYPE or CreateOptions.driverFactory')) {\n    console.error('Deployment misconfigured: no database type source. Check env files / docker env.');\n  }\n  throw e;\n}","preventionTips":["Set CUBEJS_DB_TYPE in every deployment environment (docker-compose, k8s manifests, CI)","Remember dev mode skips this check — always test with production-like env before deploys","Prefer an explicit driverFactory for programmatic setups so the config is in code","Include a startup config lint step in CI that verifies required env vars"],"tags":["config","env-var","db-type","production"],"backgroundTag":"missing-env-var","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}