JuliusBrussee/caveman · error
caveman build: source module syntax is not lexable in
Error message
caveman build: source module syntax is not lexable in ${JSON.stringify(path)} What it means
Thrown by esmSourceSpecifiers when the underlying ESM lexer (parse) throws while lexing a source module. Since dependency extraction relies purely on lexing (not full parsing/execution), any syntax the lexer rejects makes the module's import specifiers unobtainable, so the build fails fast with the file path and the lexer error as `cause`.
Solutions
- Open the file at the reported path and fix the syntax error (see the wrapped `cause`).
- Ensure only plain ESM JavaScript source is fed to the graph (pre-transpile TS/JSX).
- Re-run/repair the earlier build step that generated the corrupted file.
- Upgrade the lexer/agent package if the source uses newer JS syntax it can't yet lex.
Example fix
// before: TypeScript fed directly into the graph
import { x } from "./util"; // util.ts
// after: transpile first, graph plain ESM
import { x } from "./util.js"; // compiled util.js Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-check a file lexes as ESM using the same lexer
import { parse } from "/path/to/lexer";
import { readFile } from "node:fs/promises";
async function lexesOK(path) {
try { parse(await readFile(path, "utf8"), path); return true; } catch { return false; }
} Type guard
null
Try / catch
try {
await graph.expand();
} catch (e) {
if (e instanceof Error && e.message.includes("not lexable")) {
console.error("Fix syntax in the reported file; check (e as any).cause for the lexer error.");
}
throw e;
} Prevention
- Feed only transpiled plain ESM (not TS/JSX) into the graph.
- Keep the toolchain updated so the lexer supports new syntax.
- Run a syntax check (node --check or tsc) in CI before graph expansion.
When it happens
Trigger: specifiers -> esmSourceSpecifiers calls parse(source, path); the lexer raises on malformed syntax or non-module content (e.g. HTML, minified/broken output, unsupported syntax for the lexer version) for the file at `path`.
Common situations: Accidentally feeding generated/bundled or non-JS content into the graph; syntax newer than the lexer supports (e.g. decorators/props); a file truncated or corrupted by a failed build step; JSX/TS passed where plain ESM is expected.
Related errors
- adapter-specific build_sha256 values must differ
- agent conformance fixtures must cover claude and pi
- agent conformance mismatch
- cave_context_body_missing
- cave_stale_lock
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/d6d431a63b2aa9fc.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/source-graph.ts:276
return undefined;
}
function isRecord(value: unknown): value is Record<string, unknown> {
return value !== null && typeof value === "object" && !Array.isArray(value);
}
function isPathWithin(root: string, candidate: string): boolean {
const child = relative(root, candidate);
return child === "" || (!isAbsolute(child) && child !== ".." &&
!child.startsWith("../") && !child.startsWith("..\\"));
}
function esmSourceSpecifiers(source: string, path: string): string[] {
let imports: ReturnType<typeof parse>[0];
try {
[imports] = parse(source, path);
} catch (error) {
throw new Error(
`caveman build: source module syntax is not lexable in ${JSON.stringify(path)}`,
{ cause: error },
);
}
const specifiers: string[] = [];
for (const item of imports) {
if (item.d === -2) continue; // import.meta is metadata, not a dependency.
if (item.n === undefined) {
throw new Error(`caveman build: computed source dependency is not lockable in ${JSON.stringify(path)}`);
}
specifiers.push(item.n);
}
return specifiers;
}
function typescriptSourceSyntax(
source: string,
path: string,View on GitHub (pinned to 3ee70a1026)