{"record":{"id":"595b5156f7201bef","repo":"coleam00/Archon","slug":"enoent","errorCode":"ENOENT","errorMessage":"Failed to read version: package.json not found (bad installation?)","messagePattern":"Failed to read version: package\\.json not found \\(bad installation\\?\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/version.ts","lineNumber":42,"sourceCode":"interface PackageJson {\n  name: string;\n  version: string;\n}\n\n/**\n * Get version for development mode (reads package.json)\n */\nasync function getDevVersion(): Promise<{ name: string; version: string }> {\n  // Read root package.json (monorepo version), not the CLI package's own\n  const pkgPath = join(SCRIPT_DIR, '../../../../package.json');\n\n  let content: string;\n  try {\n    content = await readFile(pkgPath, 'utf-8');\n  } catch (error) {\n    const err = error as NodeJS.ErrnoException;\n    if (err.code === 'ENOENT') {\n      throw new Error('Failed to read version: package.json not found (bad installation?)');\n    } else if (err.code === 'EACCES') {\n      throw new Error('Failed to read version: permission denied reading package.json');\n    }\n    throw new Error(`Failed to read version: ${err.message}`);\n  }\n\n  let pkg: PackageJson;\n  try {\n    pkg = JSON.parse(content) as PackageJson;\n  } catch (_error) {\n    throw new Error('Failed to read version: package.json is malformed');\n  }\n\n  return { name: pkg.name, version: pkg.version };\n}\n\n/**\n * Get the git commit hash at runtime (dev mode).","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/cli/src/commands/version.ts#L24-L60","documentation":"getDevVersion reads package.json from the installation to determine the dev/build version; when readFile fails with ENOENT it translates that into this explicit error, indicating the CLI was installed or packaged without package.json — a broken installation. This is a boundary translation so the user sees a meaningful message instead of a raw Node ENOENT stack.","triggerScenarios":"devInfo -> getDevVersion calls readFile(pkgPath) and Node rejects with code 'ENOENT': the resolved package.json path does not exist because the binary was moved out of its package tree, a partial/failed install, a stripped production bundle, or PKG_PATH resolving to the wrong directory (e.g. run from a copied standalone binary).","commonSituations":"Installing via a copied binary without its package layout; npm/bun install interrupted mid-extract; Docker image built with .dockerignore excluding package.json; running the CLI from a relocated symlink whose target tree is missing.","solutions":["Reinstall archon cleanly (bun install -g / npm i -g the package) so package.json ships with the installation.","Verify the file exists at the location the binary resolves (`node -e \"console.log(require.resolve('.../package.json'))\"` or check the install dir).","If using a packaged standalone binary, ensure the packaging step includes package.json in the bundle.","Check PATH/symlinks point at the real install directory, not a stale copy."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs';\nconst pkgPath = new URL('../package.json', import.meta.url).pathname;\nif (!existsSync(pkgPath)) {\n  throw new Error(`Installation incomplete: ${pkgPath} missing — reinstall the package before running version info`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const info = await devInfo();\n} catch (err) {\n  if (err instanceof Error && err.message.includes('package.json not found (bad installation?)')) {\n    // trigger a clean reinstall of the package\n  } else throw err;\n}","preventionTips":["Install via the package manager (npm/bun install -g), not by copying binaries out of node_modules.","Keep package.json out of .dockerignore when building images that run version info.","Let interrupted installs fail loudly and rerun them rather than running from a half-extracted tree.","Check symlinks on PATH point at the real install directory."],"tags":["filesystem","installation","enoent","version"],"backgroundTag":"missing-package-json","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}