{"record":{"id":"12414e210e6ab3dd","repo":"JuliusBrussee/caveman","slug":"package-not-found","errorCode":null,"errorMessage":"package not found","messagePattern":"package not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/source-graph.ts","lineNumber":152,"sourceCode":"  if (target === undefined || !target.startsWith(\"./\")) {\n    throw new Error(\"import export not found\");\n  }\n  const packageRoot = dirname(packageJSONPath);\n  const absolute = resolve(packageRoot, target);\n  const relativeTarget = relative(packageRoot, absolute);\n  if (relativeTarget === \"..\" || relativeTarget.startsWith(\"../\") || relativeTarget.startsWith(\"..\\\\\")) {\n    throw new Error(\"package export escapes package root\");\n  }\n  return absolute;\n}\n\nfunction dependencyPackageRoot(specifier: string, importer: string): string {\n  return dirname(resolvePackageJSON(barePackageName(specifier), importer));\n}\n\nfunction resolvePackageJSON(packageName: string, importer: string): string {\n  const packageJSONPath = findPackageJSON(packageName, pathToFileURL(importer));\n  if (packageJSONPath === undefined) throw new Error(\"package not found\");\n  return packageJSONPath;\n}\n\nasync function collectPackageClosure(\n  packageRoot: string,\n  files: Set<string>,\n  visitedRoots: Set<string>,\n): Promise<void> {\n  const canonicalRoot = await realpath(packageRoot);\n  if (visitedRoots.has(canonicalRoot)) return;\n  visitedRoots.add(canonicalRoot);\n  // Resolve dependency edges from the physical package location. pnpm exposes\n  // the project dependency as a symlink, while its private dependency links\n  // live beside the physical package under node_modules/.pnpm.\n  const packageJSONPath = resolve(canonicalRoot, \"package.json\");\n  const packageJSON = JSON.parse(await readFile(packageJSONPath, \"utf8\")) as {\n    dependencies?: Record<string, unknown>;\n    optionalDependencies?: Record<string, unknown>;","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/source-graph.ts#L134-L170","documentation":"Thrown by resolvePackageJSON when findPackageJSON cannot locate a package.json for the requested bare package name starting from the importer's location via Node's resolution (pathToFileURL(importer) as the parent). The package is not installed or not resolvable from the importing file's location.","triggerScenarios":"packageJSONPath or dependencyPackageRoot calls resolvePackageJSON(barePackageName(specifier), importer) and the lookup walks up from the importer without finding the package's package.json (findPackageJSON returned undefined).","commonSituations":"Dependency not installed (missing node_modules after a fresh clone); dependency listed in code but not in package.json; importing an optional/peer dependency that isn't installed; pnpm/yarn PnP strictness hiding packages not declared by the importer.","solutions":["Run the package manager install (npm install / pnpm install / yarn) to restore node_modules.","Add the missing package to package.json dependencies (or devDependencies) and install.","Verify the specifier's package name is spelled correctly (case and scope).","If it's an optional/peer dependency, install it explicitly or guard the import."],"exampleFix":"// before\nimport { x } from \"left-pad-strict\"; // not in package.json\n\n// after\n// npm install left-pad-strict\nimport { x } from \"left-pad-strict\";","handlingStrategy":"validation","validationCode":"import { createRequire } from \"node:module\";\nfunction packageIsResolvable(name, importer) {\n  try { createRequire(importer).resolve(name); return true; }\n  catch { return false;\n  }\n}","typeGuard":"null","tryCatchPattern":"try {\n  await graph.expand();\n} catch (e) {\n  if (e instanceof Error && e.message === \"package not found\") {\n    console.error(\"Dependency is not installed or not resolvable; run your package manager install and add it to package.json.\");\n  }\n  throw e;\n}","preventionTips":["Always run the package manager install after pulling changes.","Keep imports and package.json dependencies in sync (lint with import/no-extraneous / depcheck).","Install declared peer/optional dependencies explicitly in dev environments."],"tags":["module-resolution","dependency","build"],"backgroundTag":"missing-dependency","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"}