{"record":{"id":"23a2b05c414b007e","repo":"cube-js/cube","slug":"configure-file-must-export-configuration-as-defaul","errorCode":null,"errorMessage":"Configure file must export configuration as default.","messagePattern":"Configure file must export configuration as default\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-server/src/server/container.ts","lineNumber":331,"sourceCode":"    const script = new vm.Script(content);\n    script.runInNewContext(\n      {\n        require,\n        console,\n        // Workaround for ES5 exports\n        exports\n      },\n      {\n        filename: 'cube.js',\n        displayErrors: true,\n      }\n    );\n\n    if (exports.default) {\n      return exports.default;\n    }\n\n    throw new Error(\n      'Configure file must export configuration as default.'\n    );\n  }\n\n  protected async loadConfigurationFromPythonFile(): Promise<CreateOptions> {\n    const content = await fsAsync.readFile(\n      path.join(process.cwd(), 'cube.py'),\n      'utf-8'\n    );\n\n    if (this.configuration.debug) {\n      console.log('Loaded python configuration file', content);\n    }\n\n    return this.loadConfigurationFromPythonMemory(content);\n  }\n\n  protected async loadConfigurationFromPythonMemory(content: string): Promise<CreateOptions> {","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-server/src/server/container.ts#L313-L349","documentation":"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`.","triggerScenarios":"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`.","commonSituations":"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`.","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"],"exampleFix":"// before\nmodule.exports = {\n  driverFactory: () => new PostgresDriver({}),\n};\n\n// after\nexport default {\n  driverFactory: () => new PostgresDriver({}),\n};","handlingStrategy":"validation","validationCode":"// check before relying on in-memory config loading\nconst mod = require('./cube.ts-compiled');\nif (!mod.default) {\n  throw new Error('Config module must use export default');\n}","typeGuard":"function hasDefaultExport(m: unknown): m is { default: Record<string, unknown> } {\n  return typeof m === 'object' && m !== null && 'default' in m;\n}","tryCatchPattern":"try {\n  await server.listen();\n} catch (e) {\n  if (e.message === 'Configure file must export configuration as default.') {\n    console.error('Add `export default { ... }` to your TypeScript config');\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["configuration","default-export","esm-cjs"],"backgroundTag":"missing-default-export","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}