cube-js/cube · error

Undefined cube '${cube}'

Error message

Undefined cube '${cube}'

What it means

QueryFactory.createQuery is keyed by cube name; it throws when the requested cube has no mapping in cubeToQueryClass. This means the cube name passed doesn't match any cube registered in the factory (built from the compiled schema's dbType/dialect mapping).

Source

Thrown at packages/cubejs-schema-compiler/src/adapter/QueryFactory.ts:9

export class QueryFactory {
  public constructor(
    private cubeToQueryClass: Record<string, any>,
  ) {
  }

  public createQuery(cube: string, compilers: any, queryOptions: any) {
    if (!(cube in this.cubeToQueryClass)) {
      throw new Error(`Undefined cube '${cube}'`);
    }
    const QueryClass = this.cubeToQueryClass[cube];
    if (!QueryClass) {
      throw new Error(`Undefined dbType or dialectClass for '${cube}'`);
    }
    return new QueryClass(compilers, queryOptions);
  }
}

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Check the exact cube name against your schema files (name matches the cube/view declaration)
  2. Recompile/reload the schema to ensure the cube exists and compiled successfully
  3. Verify the cube's dbType/dialect is defined so the factory registers a mapping for it

Example fix

// before
factory.createQuery('Orders ', compilers, options);
// after
factory.createQuery('Orders', compilers, options);
Defensive patterns

Strategy: validation

Validate before calling

const compilerApi = await prepareCompiler({ schemaPath });
const cubes = Object.keys(compilerApi.cubeEvaluator.cubeNames());
if (!cubes.includes(cube)) throw new Error(`Cube ${cube} not in schema; known: ${cubes.join(',')}`);

Try / catch

try { return factory.createQuery(cube, compilers, options); } catch (e) { if (e.message.startsWith('Undefined cube')) { /* surface list of valid cubes */ } throw e; }

Prevention

When it happens

Trigger: Calling queryFactory.createQuery(cube, compilers, queryOptions) with a cube string not present as a key in cubeToQueryClass — e.g. a misspelled cube name or a cube absent from the compiled schema.

Common situations: Typo in the cube name when creating a query programmatically; querying a cube that failed to compile or was renamed; using a cube name with different casing.

Related errors


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