JuliusBrussee/caveman · error
invalid scoped package
Error message
invalid scoped package
What it means
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.
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.
Example fix
// before import x from "@scope"; // after import x from "@scope/pkg";
Defensive patterns
Strategy: validation
Validate before calling
function isValidScopedSpecifier(specifier) {
const m = /^@([^/\s]+)\/([^/\s]+)/.exec(specifier);
return !!m && m[1] !== "" && m[2] !== "";
} Type guard
function isScopedSpecifier(s: string): s is `@${string}/${string}` {
return /^@[^/]+\/[^/]+/.test(s);
} Try / catch
try {
await graph.expand();
} catch (e) {
if (e instanceof Error && e.message === "invalid scoped package") {
console.error("Specifier starts with @ but lacks a package name; expected @scope/name.");
}
throw e;
} Prevention
- 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.
When it happens
Trigger: packageName or dependencyPackageRoot calls barePackageName(specifier) with a specifier like "@scope", "@scope/", or "@/x" where parts.length < 2 or parts[1] === "".
Common situations: 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.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- invalid package
- apiKey, baseURL, and agent are required
- arm must be or
- artifact_id is required
- artifactId is required
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/d74bc9eb130067d7.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/source-graph.ts:211
async function collectPackageFiles(directory: string, files: Set<string>): Promise<void> {
const entries = await opendir(directory);
for await (const entry of entries) {
if (entry.name === "node_modules" || entry.name === ".git") continue;
const path = resolve(directory, entry.name);
if (entry.isDirectory()) {
await collectPackageFiles(path, files);
} else if (entry.isFile()) {
files.add(path);
} else if (entry.isSymbolicLink()) {
throw new Error(`caveman build: package artifact symlink is not lockable: ${JSON.stringify(path)}`);
}
}
}
function barePackageName(specifier: string): string {
const parts = specifier.split("/");
if (specifier.startsWith("@")) {
if (parts.length < 2 || parts[1] === "") throw new Error("invalid scoped package");
return `${parts[0]}/${parts[1]}`;
}
if (parts[0] === "") throw new Error("invalid package");
return parts[0]!;
}
function resolvePackageExport(exportsValue: unknown, subpath: string): string | undefined {
if (typeof exportsValue === "string" || Array.isArray(exportsValue)) {
return subpath === "." ? resolveConditionalExport(exportsValue) : undefined;
}
if (!isRecord(exportsValue)) return undefined;
const keys = Object.keys(exportsValue);
if (!keys.some((key) => key.startsWith("."))) {
return subpath === "." ? resolveConditionalExport(exportsValue) : undefined;
}
if (Object.hasOwn(exportsValue, subpath)) {
return resolveConditionalExport(exportsValue[subpath]);
}View on GitHub (pinned to 3ee70a1026)