{"record":{"id":"e3ef42829bb007ce","repo":"cube-js/cube","slug":"the-datasource-data-source-is-missing-in-the-de","errorCode":null,"errorMessage":"The ${dataSource} data source is missing in the declared CUBEJS_DATASOURCES.","messagePattern":"The (.+?) data source is missing in the declared CUBEJS_DATASOURCES\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-shared/src/env.ts","lineNumber":95,"sourceCode":" */\nfunction isMultipleDataSources(): boolean {\n  // eslint-disable-next-line no-use-before-define\n  return getEnv('dataSources').length > 0;\n}\n\n/**\n * Returns the specified data source if assertions are passed, throws\n * an error otherwise.\n * @param dataSource The data source to assert.\n */\nexport function assertDataSource(dataSource = 'default'): string {\n  if (!isMultipleDataSources()) {\n    return dataSource;\n    // eslint-disable-next-line no-use-before-define\n  } else if (getEnv('dataSources').indexOf(dataSource) >= 0) {\n    return dataSource;\n  } else {\n    throw new Error(\n      `The ${\n        dataSource\n      } data source is missing in the declared CUBEJS_DATASOURCES.`\n    );\n  }\n}\n\n/**\n * Returns data source specific environment variable name.\n */\nexport function keyByDataSource(origin: string, dataSource?: string, preAggregations?: boolean): string {\n  if (dataSource) assertDataSource(dataSource);\n\n  let key: string;\n\n  if (!isMultipleDataSources() || dataSource === 'default' || !dataSource) {\n    key = origin;\n  } else {","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-shared/src/env.ts#L77-L113","documentation":"assertDataSource verifies that a requested data source is declared in the CUBEJS_DATASOURCES env variable when multi-datasource mode is active (i.e. CUBEJS_DATASOURCES is non-empty). If the requested source is not in the declared list, Cube throws this Error. It is invoked whenever a data source is resolved (queries, driver resolution, env key building).","triggerScenarios":"Querying or configuring a dataSource whose name does not exactly match an entry in CUBEJS_DATASOURCES, e.g. schema dataSource('postgres') while CUBEJS_DATASOURCES=orders,inventory, or passing 'default' explicitly in multi-datasource mode without declaring it.","commonSituations":"Case or spelling mismatches between schema dataSource() calls and CUBEJS_DATASOURCES (Postgres vs postgres); renaming a data source in the schema without updating CUBEJS_DATASOURCES; forgetting to add a newly introduced data source to the env list; relying on the implicit 'default' source while multi-datasource mode is on.","solutions":["Add the missing data source name to CUBEJS_DATASOURCES (comma-separated), matching the exact case used in the schema.","Fix the dataSource(...) name in the data model so it matches an already-declared entry.","If you do not actually use multiple data sources, remove CUBEJS_DATASOURCES so single-datasource mode is active.","Restart the Cube process after changing CUBEJS_DATASOURCES so the env is re-read."],"exampleFix":"// before (.env)\nCUBEJS_DATASOURCES=orders\n\n// schema.js\ncube('Sales', { dataSource: 'inventory', ... });\n\n// after (.env)\nCUBEJS_DATASOURCES=orders,inventory\n\n// schema.js\ncube('Sales', { dataSource: 'inventory', ... });","handlingStrategy":"validation","validationCode":"const declared = (process.env.CUBEJS_DATASOURCES || '').split(',').map(s => s.trim()).filter(Boolean);\nconst used = ['orders', 'inventory']; // dataSource(...) names from your schema\nconst missing = used.filter(d => declared.length > 0 && !declared.includes(d));\nif (missing.length) {\n  throw new Error(`Data sources not declared in CUBEJS_DATASOURCES: ${missing.join(', ')}`);\n}","typeGuard":"function isDeclaredDataSource(name: string): boolean {\n  const declared = (process.env.CUBEJS_DATASOURCES || '').split(',').map(s => s.trim()).filter(Boolean);\n  return declared.length === 0 || declared.includes(name);\n}","tryCatchPattern":"try {\n  await cubeServer.run();\n} catch (e) {\n  if (e.message.includes('data source is missing in the declared CUBEJS_DATASOURCES')) {\n    console.error(`Add the data source to CUBEJS_DATASOURCES (exact case): ${e.message}`);\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Keep CUBEJS_DATASOURCES and schema dataSource(...) names in sync, byte-for-byte.","When adding a new data source to the schema, update CUBEJS_DATASOURCES in the same change.","Remember 'default' must be listed explicitly once CUBEJS_DATASOURCES is non-empty.","Restart Cube after changing CUBEJS_DATASOURCES; add an env pre-flight check to CI."],"tags":["configuration","datasource","env-var","multi-datasource"],"backgroundTag":"missing-env-var","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}