{"record":{"id":"2ddc8e3de9b689ab","repo":"stablyai/orca","slug":"could-not-find-package-json-for-packagename","errorCode":null,"errorMessage":"Could not find package.json for ${packageName}","messagePattern":"Could not find package\\.json for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/packaged-runtime-node-modules.cjs","lineNumber":110,"sourceCode":"  }\n  try {\n    return requireFromProject.resolve(`${packageName}/package.json`, { paths: [fromDir] })\n  } catch {\n    let entryPath\n    try {\n      entryPath = requireFromProject.resolve(packageName, { paths: [fromDir] })\n    } catch {\n      throw new Error(`Could not resolve package ${packageName} from ${fromDir}`)\n    }\n    let dir = dirname(entryPath)\n    while (dir !== dirname(dir)) {\n      const packageJsonPath = join(dir, 'package.json')\n      if (existsSync(packageJsonPath)) {\n        return packageJsonPath\n      }\n      dir = dirname(dir)\n    }\n    throw new Error(`Could not find package.json for ${packageName}`)\n  }\n}\n\nfunction readPackage(packageName, fromDir = projectDir) {\n  const packageJsonPath = resolvePackageJsonPath(packageName, fromDir)\n  const packageDir = realpathSync(dirname(packageJsonPath))\n  const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'))\n  return {\n    name: packageJson.name ?? packageName,\n    packageDir,\n    dependencies: Object.keys(packageJson.dependencies ?? {})\n  }\n}\n\nfunction isKnownOmittedServeSimDependency(packageName, fromDir) {\n  if (packageName !== 'inspect-webkit') {\n    return false\n  }","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/packaged-runtime-node-modules.cjs#L92-L128","documentation":"The `resolvePackageJsonPath` function successfully resolved the package's entry point via `require.resolve(packageName)` but then walked up the entire directory tree from that entry point without finding a package.json. This is an unusual state — every npm/pnpm package should have a package.json at its root. The walk goes from `dirname(entryPath)` up to the filesystem root.","triggerScenarios":"A package whose main entry file is a standalone JS file not inside a package directory with a package.json. A symlink or monorepo setup where the resolved entry points outside the package's own directory. A corrupted or partial install where package.json was deleted but the entry file remains.","commonSituations":"pnpm symlink edge cases where `require.resolve` follows a symlink to a hoisted location outside the package directory. A package with a non-standard layout where the entry file is not under the package root. Manual file manipulation that deleted package.json. Very rare in practice.","solutions":["Check `entryPath` — log the resolved path to see where `require.resolve(packageName)` is pointing.","If it's a pnpm symlink issue, verify the package's node_modules entry has its package.json: `ls node_modules/.pnpm/package@version/node_modules/package/package.json`.","Reinstall the package: `pnpm install --force` to fix a corrupted install.","If the package genuinely has no package.json (custom/internal), add one at its root directory."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify package.json exists at the package root\nimport { existsSync } from 'fs'\nimport { dirname, join } from 'path'\nfunction findPackageJsonUpFrom(entryPath) {\n  let dir = dirname(entryPath)\n  while (dir !== dirname(dir)) {\n    if (existsSync(join(dir, 'package.json'))) return join(dir, 'package.json')\n    dir = dirname(dir)\n  }\n  return null\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify installs with `pnpm install --force` if you suspect corruption.","Avoid manual deletion of package.json files in node_modules.","For pnpm, check that symlinks in node_modules point to valid package directories in the .pnpm store."],"tags":["packaging","node-modules","module-resolution","package-json","pnpm"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}