cube-js/cube · error
Configure file must export configuration as default.
Error message
Configure file must export configuration as default.
What it means
Cube loaded the configuration module from memory (compiled/register-hooked source, e.g. from a TypeScript or embedded config) but it did not export the CreateOptions object as the default export. Cube only reads `exports.default` from in-memory configuration modules. This enforces the convention that config files use `export default`.
Source
Thrown at packages/cubejs-server/src/server/container.ts:331
const script = new vm.Script(content);
script.runInNewContext(
{
require,
console,
// Workaround for ES5 exports
exports
},
{
filename: 'cube.js',
displayErrors: true,
}
);
if (exports.default) {
return exports.default;
}
throw new Error(
'Configure file must export configuration as default.'
);
}
protected async loadConfigurationFromPythonFile(): Promise<CreateOptions> {
const content = await fsAsync.readFile(
path.join(process.cwd(), 'cube.py'),
'utf-8'
);
if (this.configuration.debug) {
console.log('Loaded python configuration file', content);
}
return this.loadConfigurationFromPythonMemory(content);
}
protected async loadConfigurationFromPythonMemory(content: string): Promise<CreateOptions> {View on GitHub (pinned to 7d981676b3)
Solutions
- Change the config module to use a default export: `export default { ... }`
- If using CommonJS, set `module.exports.default = { ... }` or `module.exports = { default: opts }`
- Check the transpiler/interop settings (esModuleInterop / __esModule flag) so exports.default is populated
- Verify the file being loaded is the intended config file
Example fix
// before
module.exports = {
driverFactory: () => new PostgresDriver({}),
};
// after
export default {
driverFactory: () => new PostgresDriver({}),
}; Defensive patterns
Strategy: validation
Validate before calling
// check before relying on in-memory config loading
const mod = require('./cube.ts-compiled');
if (!mod.default) {
throw new Error('Config module must use export default');
} Type guard
function hasDefaultExport(m: unknown): m is { default: Record<string, unknown> } {
return typeof m === 'object' && m !== null && 'default' in m;
} Try / catch
try {
await server.listen();
} catch (e) {
if (e.message === 'Configure file must export configuration as default.') {
console.error('Add `export default { ... }` to your TypeScript config');
}
throw e;
} Prevention
- Always use `export default` in TypeScript config modules
- Avoid mixing module.exports and export default in the same file
- Enable esModuleInterop for consistent interop
- Smoke-test config loading in CI before deploy
When it happens
Trigger: A cube.ts / config module compiled and loaded via loadConfigurationFromMemory that uses `module.exports = {...}` or named exports only (`export const cube = ...`) instead of `export default`.
Common situations: Porting an older CommonJS cube.js config to the TS pipeline without converting to default export; writing `exports.config = ...`; Babel/TS interop quirks where module.exports shape lacks `.default`.
Related errors
- Configuration file must export the configuration as default.
- A user-defined contextToApiScopes function returns an incons
- A user-defined contextToApiScopes function returns a wrong s
- Unload is not configured. Please define CUBEJS_AWS_S3_OUTPUT
- Export bucket is not configured.
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/23a2b05c414b007e.
Report an issue: GitHub.