cube-js/cube · error · Error
${type} is required
Error message
${type} is required What it means
The Dev Server's /playground/test-connection endpoint resolves the env variable name that must hold the database type (CUBEJS_DB_TYPE, or CUBEJS_DS_<dataSource>_DB_TYPE for multiple data sources) via keyByDataSource, then requires the submitted `variables` object to contain a value for that key. If the variables map is missing/empty or lacks that key, it throws `${type} is required` before attempting to instantiate and test the driver. Cube needs the db type to know which driver package to load and which env keys to read.
Source
Thrown at packages/cubejs-server-core/src/core/DevServer.ts:508
[env: string]: string,
},
},
};
app.post('/playground/test-connection', catchErrors(
async (req: TestConnectionRequest, res) => {
const { dataSource, variables } = req.body || {};
// With multiple data sources enabled, we need to use
// CUBEJS_DS_<dataSource>_DB_TYPE environment variable
// instead of CUBEJS_DB_TYPE.
const type = keyByDataSource('CUBEJS_DB_TYPE', dataSource);
let driver: BaseDriver | null = null;
try {
if (!variables || !variables[type]) {
throw new Error(`${type} is required`);
}
// Backup env variables and set new ones in-place.
// We must mutate the existing process.env object (not replace it)
// because env-var holds a reference to the original object.
const backup: Record<string, string | undefined> = {};
for (const [envName, envValue] of Object.entries(variables)) {
backup[envName] = process.env[envName];
process.env[envName] = <string>envValue;
}
// With multiple data sources enabled, we need to put the dataSource
// parameter to the driver instance to read an appropriate set of
// driver configuration parameters. It can be undefined if multiple
// data source is disabled.
driver = CubejsServerCore.createDriver(
<DatabaseType>variables[type],View on GitHub (pinned to 7d981676b3)
Solutions
- Include the database type in the request variables, e.g. { variables: { CUBEJS_DB_TYPE: 'postgres', ... } }
- For multiple data sources, send the dataSource-specific key, e.g. { variables: { CUBEJS_DS_MYDS_DB_TYPE: 'mysql' } } together with dataSource in the body
- Fix the client/UI to always populate the db type field before calling the endpoint
- Set CUBEJS_DB_TYPE in the environment as a baseline so tooling can default to it
Example fix
// before
curl -X POST /playground/test-connection -d '{"variables":{"CUBEJS_DB_HOST":"localhost"}}'
// after
curl -X POST /playground/test-connection -d '{"variables":{"CUBEJS_DB_TYPE":"postgres","CUBEJS_DB_HOST":"localhost"}}' Defensive patterns
Strategy: validation
Validate before calling
async function testConnectionSafe(body) {
const { dataSource, variables } = body || {};
const type = dataSource ? `CUBEJS_DS_${dataSource.toUpperCase()}_DB_TYPE` : 'CUBEJS_DB_TYPE';
if (!variables || !variables[type]) {
throw new Error(`${type} is required by /playground/test-connection`);
}
return fetch('/playground/test-connection', { method: 'POST', body: JSON.stringify(body) });
} Type guard
function hasDbTypeVariables(v) {
return typeof v === 'object' && v !== null && typeof v.CUBEJS_DB_TYPE === 'string' && v.CUBEJS_DB_TYPE.length > 0;
} Try / catch
try {
const res = await fetch('/playground/test-connection', {...});
if (!res.ok) throw new Error((await res.json()).error);
} catch (e) {
if (/DB_TYPE is required/.test(String(e))) {
// prompt the user to pick a database type before retrying
}
} Prevention
- Always include CUBEJS_DB_TYPE in the variables payload sent to the test-connection endpoint
- For multiple data sources, compute the per-source key CUBEJS_DS_<DS>_DB_TYPE before sending
- Validate the request body client-side before posting
- Default the db type from the server environment when the form field is empty
When it happens
Trigger: POSTing to /playground/test-connection with a body whose `variables` is undefined, or variables lacking the key 'CUBEJS_DB_TYPE' (or 'CUBEJS_DS_<ds>_DB_TYPE' when a dataSource is passed and multiple data sources are enabled). This happens from the Developer Playground 'Test connection' UI when the database type field was not filled in.
Common situations: Using the Playground's connection-test form without selecting a database type; custom tooling calling the endpoint without the variables payload; multi-data-source setups where the request omits the per-data-source DB type variable; typos in the env variable key sent by the client.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- Wrong driver
- Timezone must not be empty
- You have to select at least one table
- Unknown schema format. Must be one of ${Object.values(Schema
- Unexpected CreateOptions.driverFactory result value. Must be
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/f91adf1aaa8be2d2.
Report an issue: GitHub.