JuliusBrussee/caveman · error
invalid package
Error message
invalid package
What it means
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.
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.
Example fix
// before
const spec = `/node_modules/${name}`;
// after
const spec = name; // bare package specifier Defensive patterns
Strategy: validation
Validate before calling
function isValidBareSpecifier(specifier) {
return typeof specifier === "string" && specifier.length > 0 && !specifier.startsWith("/") && !specifier.startsWith("@") && specifier.split("/")[0] !== "";
} Type guard
function isBareSpecifier(s: string): boolean {
return s.length > 0 && !s.startsWith(".") && !s.startsWith("/");
} Try / catch
try {
await graph.expand();
} catch (e) {
if (e instanceof Error && e.message === "invalid package") {
console.error("Specifier is a path, not a package name; use ./relative or a bare package name.");
}
throw e;
} Prevention
- 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).
When it happens
Trigger: packageName or dependencyPackageRoot calls barePackageName(specifier) where specifier.split("/")[0] === "" — e.g. "/foo/bar", "", or a specifier that is actually a filesystem path.
Common situations: 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.
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 scoped 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/abfe6caadc727c5b.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/source-graph.ts:214
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]);
}
const patterns = keys
.filter((key) => key.startsWith("./") && key.includes("*"))
.sort((left, right) => right.length - left.length);View on GitHub (pinned to 3ee70a1026)