{"record":{"id":"d74bc9eb130067d7","repo":"JuliusBrussee/caveman","slug":"invalid-scoped-package","errorCode":null,"errorMessage":"invalid scoped package","messagePattern":"invalid scoped package","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/source-graph.ts","lineNumber":211,"sourceCode":"async function collectPackageFiles(directory: string, files: Set<string>): Promise<void> {\n  const entries = await opendir(directory);\n  for await (const entry of entries) {\n    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  }","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/source-graph.ts#L193-L229","documentation":"Thrown by barePackageName when a specifier starts with \"@\" (scoped) but does not contain a valid second path segment — i.e. it's not of the form @scope/name. Scoped packages require both a scope and a package name; anything else is malformed and cannot be resolved to a package root.","triggerScenarios":"packageName or dependencyPackageRoot calls barePackageName(specifier) with a specifier like \"@scope\", \"@scope/\", or \"@/x\" where parts.length < 2 or parts[1] === \"\".","commonSituations":"Typo in an import (\"@types\" alone); string-built specifiers from dynamic imports or templating that dropped the name segment; accidentally treating an alias path (\"@/components\") as a package specifier.","solutions":["Fix the import specifier to include the package name after the scope (e.g. @scope/pkg).","If \"@/...\" is a path alias, ensure it's resolved by the bundler/tsconfig paths before reaching package resolution.","Check code that constructs specifiers dynamically for dropped segments.","Validate specifiers before passing them into the graph expansion."],"exampleFix":"// before\nimport x from \"@scope\";\n\n// after\nimport x from \"@scope/pkg\";","handlingStrategy":"validation","validationCode":"function isValidScopedSpecifier(specifier) {\n  const m = /^@([^/\\s]+)\\/([^/\\s]+)/.exec(specifier);\n  return !!m && m[1] !== \"\" && m[2] !== \"\";\n}","typeGuard":"function isScopedSpecifier(s: string): s is `@${string}/${string}` {\n  return /^@[^/]+\\/[^/]+/.test(s);\n}","tryCatchPattern":"try {\n  await graph.expand();\n} catch (e) {\n  if (e instanceof Error && e.message === \"invalid scoped package\") {\n    console.error(\"Specifier starts with @ but lacks a package name; expected @scope/name.\");\n  }\n  throw e;\n}","preventionTips":["Never import a bare scope (\"@scope\") without the package name.","Keep bundler/tsconfig path aliases (e.g. \"@/...\") distinct from package specifiers.","Validate dynamically built specifiers with a regex before resolution."],"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"}