JuliusBrussee/caveman · error

caveman build: config must export defineBuild()

Error message

caveman build: config must export defineBuild()

What it means

stageDevLockInputs imports the caveman config file freshly (bypassing the module cache) and expects it to export a BuildConfig either as the default export or as a named `config` export. The check requires a config object whose `evals` field is a string (a glob). If the module exports neither default nor `config`, or the exported value lacks a string `evals`, this error is thrown.

Solutions

  1. Export the result of defineBuild() as the default export: `export default defineBuild({...})`.
  2. Alternatively export it as `export const config = defineBuild({...})`.
  3. Ensure the `evals` field is a string glob (e.g. "evals/**/*.eval.ts").
  4. Rebuild/restart so the fresh import picks up the corrected file.

Example fix

// before
export const build = { lock: "strict", sandbox: "required", evals: "evals/*.ts" };
// after
import { defineBuild } from "@caveman/agent";
export default defineBuild({ lock: "strict", sandbox: "required", evals: "evals/*.eval.ts" });
Defensive patterns

Strategy: validation

Validate before calling

const cfg = await import("./caveman.config.ts");
const c = cfg.default ?? cfg.config;
if (!c || typeof c.evals !== "string") throw new Error("config must default-export defineBuild() with a string evals glob");

Type guard

function isBuildConfig(v: unknown): v is BuildConfig & { evals: string } {
  return typeof v === "object" && v !== null && "evals" in v && typeof (v as { evals: unknown }).evals === "string";
}

Try / catch

try {
  await stageDevLockInputs();
} catch (err) {
  if (String(err?.message).includes("config must export defineBuild()")) {
    console.error("Fix caveman.config.ts: export default defineBuild({ ... evals: 'glob' })");
  }
  throw err;
}

Prevention

When it happens

Trigger: caveman.config.ts uses a different export style (e.g. `export const build = defineBuild(...)`), omits `defineBuild()` entirely, exports only primitives, or sets `evals` to undefined/non-string; also a config file that throws or exports a promise-shaped value.

Common situations: Copy-pasting a config snippet with `export const cfg = ...` instead of `export default defineBuild({...})`; hand-written config without the defineBuild helper; a refactor renaming the export.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/620178eb66e7074c. Report an issue: GitHub.

Appendix: source

Thrown at packages/agent/src/cli.ts:676

  loaded: Awaited<ReturnType<typeof loadDevModule>>,
): Promise<boolean> {
  const lockPath = ".caveman/agent.lock.json";
  try {
    await readFile(resolve(root, lockPath));
  } catch (error) {
    if ((error as NodeJS.ErrnoException).code === "ENOENT") return false;
    throw error;
  }
  const configPath = "caveman.config.ts";
  await loaded.includeFiles([lockPath]);
  await loaded.includeSourceGraph([configPath]);
  const imported = await importFresh(resolve(loaded.rootDir, configPath)) as {
    default?: BuildConfig;
    config?: BuildConfig;
  };
  const config = imported.default ?? imported.config;
  if (!config || typeof config.evals !== "string") {
    throw new Error("caveman build: config must export defineBuild()");
  }
  const evalFiles: string[] = [];
  for await (const path of glob(config.evals, { cwd: root })) {
    evalFiles.push(resolve(root, path));
  }
  await loaded.includeSourceGraph(evalFiles);
  const sourceFiles: string[] = [];
  for (const pattern of SOURCE_PATTERNS) {
    for await (const path of glob(pattern, { cwd: root })) sourceFiles.push(resolve(root, path));
  }
  await loaded.includeFiles(sourceFiles);
  await loaded.includeOptionalFiles(PACKAGE_STATE_FILES);
  return true;
}

function firstUsefulError(error: unknown): string {
  const stack = error instanceof Error ? error.stack ?? error.message : String(error);
  return stack.split("\n").slice(0, 4).join("\n");

View on GitHub (pinned to 3ee70a1026)