{"record":{"id":"d6d431a63b2aa9fc","repo":"JuliusBrussee/caveman","slug":"caveman-build-source-module-syntax-is-not-lexable","errorCode":null,"errorMessage":"caveman build: source module syntax is not lexable in ${JSON.stringify(path)}","messagePattern":"caveman build: source module syntax is not lexable in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/source-graph.ts","lineNumber":276,"sourceCode":"  return undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n  return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction isPathWithin(root: string, candidate: string): boolean {\n  const child = relative(root, candidate);\n  return child === \"\" || (!isAbsolute(child) && child !== \"..\" &&\n    !child.startsWith(\"../\") && !child.startsWith(\"..\\\\\"));\n}\n\nfunction esmSourceSpecifiers(source: string, path: string): string[] {\n  let imports: ReturnType<typeof parse>[0];\n  try {\n    [imports] = parse(source, path);\n  } catch (error) {\n    throw new Error(\n      `caveman build: source module syntax is not lexable in ${JSON.stringify(path)}`,\n      { cause: error },\n    );\n  }\n  const specifiers: string[] = [];\n  for (const item of imports) {\n    if (item.d === -2) continue; // import.meta is metadata, not a dependency.\n    if (item.n === undefined) {\n      throw new Error(`caveman build: computed source dependency is not lockable in ${JSON.stringify(path)}`);\n    }\n    specifiers.push(item.n);\n  }\n  return specifiers;\n}\n\nfunction typescriptSourceSyntax(\n  source: string,\n  path: string,","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/source-graph.ts#L258-L294","documentation":"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`.","triggerScenarios":"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`.","commonSituations":"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.","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."],"exampleFix":"// before: TypeScript fed directly into the graph\nimport { x } from \"./util\"; // util.ts\n\n// after: transpile first, graph plain ESM\nimport { x } from \"./util.js\"; // compiled util.js","handlingStrategy":"try-catch","validationCode":"// Pre-check a file lexes as ESM using the same lexer\nimport { parse } from \"/path/to/lexer\";\nimport { readFile } from \"node:fs/promises\";\nasync function lexesOK(path) {\n  try { parse(await readFile(path, \"utf8\"), path); return true; } catch { return false; }\n}","typeGuard":"null","tryCatchPattern":"try {\n  await graph.expand();\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"not lexable\")) {\n    console.error(\"Fix syntax in the reported file; check (e as any).cause for the lexer error.\");\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["syntax","lexer","build"],"backgroundTag":"xml-parse-error","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}