cube-js/cube · error · Error
Can't find dialect for '${dataSource}' data source: ${_dbTyp
Error message
Can't find dialect for '${dataSource}' data source: ${_dbType} What it means
When the dbType is known but the driver-family lookup (e.g. by driverClass/dialect mapping) still cannot find a dialect implementation for a named data source, this Error is thrown, including both the dataSource name and the underlying _dbType.
Source
Thrown at packages/cubejs-server-core/src/core/CompilerApi.ts:344
}
// sqlGenerator.dataSource can return undefined for query without members
// Queries like this are used by api-gateway to initialize SQL API
// At the same time, those queries should use concrete dataSource, so we should be good to go with it
dataSource = compilers.compiler.withQuery(sqlGenerator, () => sqlGenerator.dataSource);
if (dataSource !== undefined) {
const _dbType = await this.getDbType(dataSource);
if (dataSource !== 'default' && dbType !== _dbType) {
// TODO consider more efficient way than instantiating query
sqlGenerator = await this.createQueryByDataSource(
compilers,
query,
dataSource,
_dbType
);
if (!sqlGenerator) {
throw new Error(
`Can't find dialect for '${dataSource}' data source: ${_dbType}`
);
}
}
}
return { sqlGenerator, compilers };
}
public async getSql(query: NormalizedQuery, options: GetSqlOptions = {}): Promise<SqlResult> {
const { includeDebugInfo, exportAnnotatedSql, preAggregationsOnly } = options;
const { sqlGenerator, compilers } = await this.getSqlGenerator(query);
const getSqlFn = () => compilers.compiler.withQuery(sqlGenerator, () => ({
external: sqlGenerator.externalPreAggregationQuery(),
sql: preAggregationsOnly ? null : sqlGenerator.buildSqlAndParams(exportAnnotatedSql),
lambdaQueries: preAggregationsOnly ? [] : sqlGenerator.buildLambdaQuery(),
timeDimensionAlias: sqlGenerator.timeDimensions[0]?.unescapedAliasName(),View on GitHub (pinned to 7d981676b3)
Solutions
- Install the official driver package for that data source's database
- Verify the dbType for that dataSource matches a supported dialect family
- Use the built-in driver class instead of a wrapper, or ensure the wrapper extends the official driver
- Log _dbType and dataSource and check the dialect registry coverage
Example fix
// before
// no clickhouse driver installed, custom wrapper used
// after
yarn add @cubejs-backend/clickhouse-driver
// and driverFactory returns new ClickHouseDriver({...}) Defensive patterns
Strategy: validation
Validate before calling
for (const [ds, driver] of Object.entries(drivers)) {
const t = await driver.dbType();
if (!dialectRegistry.has(t)) throw new Error(`Data source '${ds}' has no dialect for dbType '${t}'`);
} Type guard
const hasDialect = (dbType: string): dbType is KnownDbType => Object.prototype.hasOwnProperty.call(dialectMap, dbType);
Try / catch
try { await compilerApi.getSqlGenerator(query, ds); } catch (e) { if (/Can't find dialect for/.test(e.message)) { /* install/register dialect */ } else throw e; } Prevention
- Install official driver packages for every configured data source
- Avoid wrappers that obscure the driver class identity
- Test each data source's SQL generation at startup
- Keep driver and server versions aligned
When it happens
Trigger: Multi-tenant setups where an additional data source's driver does not map to a supported dialect — e.g. a custom driver class whose family isn't recognized, or dbType set correctly but the dialect module not installed.
Common situations: Adding a second database (e.g. ClickHouse, Databricks) without installing the driver package that registers its dialect; custom driver wrappers that change the prototype/family detection.
Related errors
- The ${dataSource} data source is missing in the declared CUB
- Dialect for '${queryOptions.externalDbType}' is not found
- Undefined dbType or dialectClass for '${cube}'
- Unknown dbType: ${dbType}
- A user-defined contextToApiScopes function returns an incons
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/337fe121c04572b5.
Report an issue: GitHub.