cube-js/cube · error · UserError

Can't resolve ${tableName}: '${table}' does not exist

Error message

Can't resolve ${tableName}: '${table}' does not exist

What it means

Same lookup path as the schema-level error, but here the schema exists while the table name (second segment) is missing from dbSchema[schema]. The driver introspected the schema but no table with that name was found.

Source

Thrown at packages/cubejs-schema-compiler/src/scaffolding/ScaffoldingSchema.ts:219

        const definition: TableData = {
          schema, table, tableDefinition, tableName
        };
        const tableizeName = inflection.tableize(this.fixCase(table));
        const parts = tableizeName.split('_');
        const tableNamesFromParts = R.range(0, parts.length - 1).map(toDrop => inflection.tableize(R.drop(toDrop, parts).join('_')));
        const names = R.uniq([table, tableizeName].concat(tableNamesFromParts));
        return names.map(n => [n, definition]);
      })
    ) as any;
  }

  public resolveTableDefinition(tableName: TableName) {
    const [schema, table] = this.parseTableName(tableName);
    if (!this.dbSchema[schema]) {
      throw new UserError(`Can't resolve ${tableName}: '${schema}' does not exist`);
    }
    if (!this.dbSchema[schema][table]) {
      throw new UserError(`Can't resolve ${tableName}: '${table}' does not exist`);
    }
    return this.dbSchema[schema][table];
  }

  protected tableSchema(tableName: TableName, includeJoins: boolean): TableSchema {
    const [schema, table] = this.parseTableName(tableName);
    const tableDefinition = this.resolveTableDefinition(tableName);
    const dimensions = this.dimensions(tableDefinition);

    return {
      cube: this.options.snakeCase ? toSnakeCase(table) : inflection.camelize(table),
      tableName,
      schema,
      table,
      measures: this.numberMeasures(tableDefinition),
      dimensions,
      joins: includeJoins ? this.joins(tableName, tableDefinition) : []
    };

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Verify the table exists: run the equivalent of SELECT from information_schema.tables for that schema
  2. Check the DB user's permissions (GRANT SELECT) so the table appears in introspection
  3. Confirm you are pointing at the correct database/environment credentials
  4. Fix casing/quoting of the table name in the request

Example fix

// before
schema.resolveTableDefinition('public.ordrs');
// after
schema.resolveTableDefinition('public.orders');
Defensive patterns

Strategy: validation

Validate before calling

const def = dbSchema?.[schema]?.[table];
if (!def) throw new Error(`Table '${schema}.${table}' not found in introspected schema`);

Type guard

const hasTable = (db: any, schema: string, table: string) => !!db?.[schema] && Object.prototype.hasOwnProperty.call(db[schema], table);

Try / catch

try { schema.resolveTableDefinition(tableName); } catch (e) { if (e instanceof UserError && /'[^']+' does not exist/.test(e.message)) { /* suggest similar tables */ } else throw e; }

Prevention

When it happens

Trigger: resolveTableDefinition called with a table that does not exist in the given schema, is not visible to the connecting DB user, or whose name differs in case/quoting from the introspected name.

Common situations: Table was dropped/renamed after schema cache was built, dev points at the wrong database, using 'users' when the real name is 'user' or '"Users"', or insufficient GRANTs hiding the table from information_schema introspection.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/82e01d70bfacb602. Report an issue: GitHub.