{"record":{"id":"7ea826b385bf9a78","repo":"lobehub/lobehub","slug":"could-not-locate-the-lobehub-cli-package-root-wal","errorCode":null,"errorMessage":"Could not locate the @lobehub/cli package root walking up from ${startDir}. The CLI install may be corrupted.","messagePattern":"Could not locate the @lobehub/cli package root walking up from (.+?)\\. The CLI install may be corrupted\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/cli/src/utils/skillLocator.ts","lineNumber":42,"sourceCode":"        // Not a readable/valid package.json — keep walking up.\n      }\n    }\n    const parent = path.dirname(dir);\n    if (parent === dir) return undefined;\n    dir = parent;\n  }\n}\n\n// startDir is anchored to this module's own location by the caller\n// (import.meta.url), never process.cwd() — resolution must not depend on\n// where the CLI happens to be invoked from.\nexport function locateBundledSkill(\n  skillName = 'agent-testing',\n  startDir: string = path.dirname(fileURLToPath(import.meta.url)),\n): BundledSkill {\n  const cliRoot = findCliRoot(startDir);\n  if (!cliRoot) {\n    throw new Error(\n      `Could not locate the @lobehub/cli package root walking up from ${startDir}. ` +\n        'The CLI install may be corrupted.',\n    );\n  }\n\n  const skillDir = path.join(cliRoot, 'skills', skillName);\n  if (!existsSync(skillDir)) {\n    throw new Error(\n      `Bundled skill \"${skillName}\" not found at ${skillDir}. ` +\n        'The @lobehub/cli install may be missing its skills/ directory.',\n    );\n  }\n\n  const pkg = JSON.parse(readFileSync(path.join(cliRoot, 'package.json'), 'utf8'));\n\n  return { cliRoot, skillDir, version: pkg.version };\n}\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/lobehub/lobehub/blob/10f24d7ade75139093a9373b364f6bc91f3cd7db/apps/cli/src/utils/skillLocator.ts#L24-L60","documentation":"Thrown by locateBundledSkill() when findCliRoot(startDir) walks up from the module's directory and reaches the filesystem root without finding a package.json whose name is '@lobehub/cli'. The skill locator anchors resolution to import.meta.url (not cwd), so this indicates the @lobehub/cli package itself is missing its identifying package.json — typically a corrupted, partial, or repackaged install.","triggerScenarios":"locateBundledSkill() called during a CLI invocation, and no ancestor directory of the skillLocator module contains a package.json with name === '@lobehub/cli'.","commonSituations":"Global/npx install where the published tarball omitted package.json or renamed the package; a bundler (webpack/esbuild) rewrote or stripped package.json; the CLI was cloned/copied without package.json; symlink layouts where import.meta.url resolves outside the real package tree.","solutions":["Reinstall the CLI cleanly: `npm i -g @lobehub/cli` (or the documented install command) to restore package.json.","If running from a monorepo checkout, ensure apps/cli/package.json exists and has \"name\": \"@lobehub/cli\".","Avoid bundling the CLI in a way that strips or rewrites the identifying package.json.","If the install location is non-standard, verify the directory hierarchy contains the expected package.json at or above the dist folder."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { existsSync, readFileSync } from 'node:fs';\nimport path from 'node:path';\nfunction cliRootFound(startDir: string): boolean {\n  let dir = startDir;\n  while (true) {\n    const pkgPath = path.join(dir, 'package.json');\n    if (existsSync(pkgPath)) {\n      try { const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')); if (pkg?.name === '@lobehub/cli') return true; } catch {}\n    }\n    const parent = path.dirname(dir);\n    if (parent === dir) return false;\n    dir = parent;\n  }\n}\nif (!cliRootFound(__dirname)) console.error('CLI install missing @lobehub/cli package.json — reinstall.');","typeGuard":null,"tryCatchPattern":"try { locateBundledSkill('agent-testing'); } catch (e) { if (e instanceof Error && /Could not locate the @lobehub\\/cli package root/.test(e.message)) { console.error('Reinstall the CLI: npm i -g @lobehub/cli'); return; } throw e; }","preventionTips":["Install the CLI from the official package; avoid repackaging that strips package.json.","If bundling the CLI for distribution, ensure the identifying package.json is preserved at the package root.","In dev checkouts, confirm apps/cli/package.json exists with name '@lobehub/cli'."],"tags":["cli","skill-locator","install","corruption"],"backgroundTag":null,"analyzedSha":"10f24d7ade75139093a9373b364f6bc91f3cd7db","analyzedAt":"2026-08-12T11:43:19.543Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}