JuliusBrussee/caveman · error

package not found

Error message

package not found

What it means

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.

Solutions

  1. Run the package manager install (npm install / pnpm install / yarn) to restore node_modules.
  2. Add the missing package to package.json dependencies (or devDependencies) and install.
  3. Verify the specifier's package name is spelled correctly (case and scope).
  4. If it's an optional/peer dependency, install it explicitly or guard the import.

Example fix

// before
import { x } from "left-pad-strict"; // not in package.json

// after
// npm install left-pad-strict
import { x } from "left-pad-strict";
Defensive patterns

Strategy: validation

Validate before calling

import { createRequire } from "node:module";
function packageIsResolvable(name, importer) {
  try { createRequire(importer).resolve(name); return true; }
  catch { return false;
  }
}

Type guard

null

Try / catch

try {
  await graph.expand();
} catch (e) {
  if (e instanceof Error && e.message === "package not found") {
    console.error("Dependency is not installed or not resolvable; run your package manager install and add it to package.json.");
  }
  throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/12414e210e6ab3dd. Report an issue: GitHub.

Appendix: source

Thrown at packages/agent/src/source-graph.ts:152

  if (target === undefined || !target.startsWith("./")) {
    throw new Error("import export not found");
  }
  const packageRoot = dirname(packageJSONPath);
  const absolute = resolve(packageRoot, target);
  const relativeTarget = relative(packageRoot, absolute);
  if (relativeTarget === ".." || relativeTarget.startsWith("../") || relativeTarget.startsWith("..\\")) {
    throw new Error("package export escapes package root");
  }
  return absolute;
}

function dependencyPackageRoot(specifier: string, importer: string): string {
  return dirname(resolvePackageJSON(barePackageName(specifier), importer));
}

function resolvePackageJSON(packageName: string, importer: string): string {
  const packageJSONPath = findPackageJSON(packageName, pathToFileURL(importer));
  if (packageJSONPath === undefined) throw new Error("package not found");
  return packageJSONPath;
}

async function collectPackageClosure(
  packageRoot: string,
  files: Set<string>,
  visitedRoots: Set<string>,
): Promise<void> {
  const canonicalRoot = await realpath(packageRoot);
  if (visitedRoots.has(canonicalRoot)) return;
  visitedRoots.add(canonicalRoot);
  // Resolve dependency edges from the physical package location. pnpm exposes
  // the project dependency as a symlink, while its private dependency links
  // live beside the physical package under node_modules/.pnpm.
  const packageJSONPath = resolve(canonicalRoot, "package.json");
  const packageJSON = JSON.parse(await readFile(packageJSONPath, "utf8")) as {
    dependencies?: Record<string, unknown>;
    optionalDependencies?: Record<string, unknown>;

View on GitHub (pinned to 3ee70a1026)