{"record":{"id":"abfe6caadc727c5b","repo":"JuliusBrussee/caveman","slug":"invalid-package","errorCode":null,"errorMessage":"invalid package","messagePattern":"invalid package","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/source-graph.ts","lineNumber":214,"sourceCode":"    if (entry.name === \"node_modules\" || entry.name === \".git\") continue;\n    const path = resolve(directory, entry.name);\n    if (entry.isDirectory()) {\n      await collectPackageFiles(path, files);\n    } else if (entry.isFile()) {\n      files.add(path);\n    } else if (entry.isSymbolicLink()) {\n      throw new Error(`caveman build: package artifact symlink is not lockable: ${JSON.stringify(path)}`);\n    }\n  }\n}\n\nfunction barePackageName(specifier: string): string {\n  const parts = specifier.split(\"/\");\n  if (specifier.startsWith(\"@\")) {\n    if (parts.length < 2 || parts[1] === \"\") throw new Error(\"invalid scoped package\");\n    return `${parts[0]}/${parts[1]}`;\n  }\n  if (parts[0] === \"\") throw new Error(\"invalid package\");\n  return parts[0]!;\n}\n\nfunction resolvePackageExport(exportsValue: unknown, subpath: string): string | undefined {\n  if (typeof exportsValue === \"string\" || Array.isArray(exportsValue)) {\n    return subpath === \".\" ? resolveConditionalExport(exportsValue) : undefined;\n  }\n  if (!isRecord(exportsValue)) return undefined;\n  const keys = Object.keys(exportsValue);\n  if (!keys.some((key) => key.startsWith(\".\"))) {\n    return subpath === \".\" ? resolveConditionalExport(exportsValue) : undefined;\n  }\n  if (Object.hasOwn(exportsValue, subpath)) {\n    return resolveConditionalExport(exportsValue[subpath]);\n  }\n  const patterns = keys\n    .filter((key) => key.startsWith(\"./\") && key.includes(\"*\"))\n    .sort((left, right) => right.length - left.length);","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/source-graph.ts#L196-L232","documentation":"Thrown by barePackageName when a non-scoped specifier's first path segment is empty — i.e. the specifier starts with \"/\" (absolute path) or is otherwise an empty package name. Bare package specifiers must start with a package name, not a path separator.","triggerScenarios":"packageName or dependencyPackageRoot calls barePackageName(specifier) where specifier.split(\"/\")[0] === \"\" — e.g. \"/foo/bar\", \"\", or a specifier that is actually a filesystem path.","commonSituations":"Passing an absolute file path where a bare package specifier is expected; concatenation bugs producing a leading slash; importing \"\" via a variable that is undefined/empty.","solutions":["Use relative (\"./...\") or proper bare specifiers instead of absolute paths in imports.","Fix the code building the specifier so the package name is non-empty and doesn't start with \"/\".","Check for undefined/empty variables interpolated into import specifiers.","Pre-validate specifiers (must match /^(@[^/]+\\/)?[^/]+/) before resolution."],"exampleFix":"// before\nconst spec = `/node_modules/${name}`;\n\n// after\nconst spec = name; // bare package specifier","handlingStrategy":"validation","validationCode":"function isValidBareSpecifier(specifier) {\n  return typeof specifier === \"string\" && specifier.length > 0 && !specifier.startsWith(\"/\") && !specifier.startsWith(\"@\") && specifier.split(\"/\")[0] !== \"\";\n}","typeGuard":"function isBareSpecifier(s: string): boolean {\n  return s.length > 0 && !s.startsWith(\".\") && !s.startsWith(\"/\");\n}","tryCatchPattern":"try {\n  await graph.expand();\n} catch (e) {\n  if (e instanceof Error && e.message === \"invalid package\") {\n    console.error(\"Specifier is a path, not a package name; use ./relative or a bare package name.\");\n  }\n  throw e;\n}","preventionTips":["Use \"./\" or \"../\" prefixes for file imports; never absolute filesystem paths.","Guard variables interpolated into import specifiers against being empty/undefined.","Lint with rules that disallow absolute imports (import/no-absolute-path)."],"tags":["module-resolution","validation","specifier"],"backgroundTag":"invalid-identifier-format","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"}