lobehub/lobehub · error · Error

Could not locate the @lobehub/cli package root walking up fr

Error message

Could not locate the @lobehub/cli package root walking up from ${startDir}. The CLI install may be corrupted.

What it means

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.

Source

Thrown at apps/cli/src/utils/skillLocator.ts:42

        // Not a readable/valid package.json — keep walking up.
      }
    }
    const parent = path.dirname(dir);
    if (parent === dir) return undefined;
    dir = parent;
  }
}

// startDir is anchored to this module's own location by the caller
// (import.meta.url), never process.cwd() — resolution must not depend on
// where the CLI happens to be invoked from.
export function locateBundledSkill(
  skillName = 'agent-testing',
  startDir: string = path.dirname(fileURLToPath(import.meta.url)),
): BundledSkill {
  const cliRoot = findCliRoot(startDir);
  if (!cliRoot) {
    throw new Error(
      `Could not locate the @lobehub/cli package root walking up from ${startDir}. ` +
        'The CLI install may be corrupted.',
    );
  }

  const skillDir = path.join(cliRoot, 'skills', skillName);
  if (!existsSync(skillDir)) {
    throw new Error(
      `Bundled skill "${skillName}" not found at ${skillDir}. ` +
        'The @lobehub/cli install may be missing its skills/ directory.',
    );
  }

  const pkg = JSON.parse(readFileSync(path.join(cliRoot, 'package.json'), 'utf8'));

  return { cliRoot, skillDir, version: pkg.version };
}

View on GitHub (pinned to 10f24d7ade)

Solutions

  1. Reinstall the CLI cleanly: `npm i -g @lobehub/cli` (or the documented install command) to restore package.json.
  2. If running from a monorepo checkout, ensure apps/cli/package.json exists and has "name": "@lobehub/cli".
  3. Avoid bundling the CLI in a way that strips or rewrites the identifying package.json.
  4. If the install location is non-standard, verify the directory hierarchy contains the expected package.json at or above the dist folder.
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync, readFileSync } from 'node:fs';
import path from 'node:path';
function cliRootFound(startDir: string): boolean {
  let dir = startDir;
  while (true) {
    const pkgPath = path.join(dir, 'package.json');
    if (existsSync(pkgPath)) {
      try { const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')); if (pkg?.name === '@lobehub/cli') return true; } catch {}
    }
    const parent = path.dirname(dir);
    if (parent === dir) return false;
    dir = parent;
  }
}
if (!cliRootFound(__dirname)) console.error('CLI install missing @lobehub/cli package.json — reinstall.');

Try / catch

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; }

Prevention

When it happens

Trigger: locateBundledSkill() called during a CLI invocation, and no ancestor directory of the skillLocator module contains a package.json with name === '@lobehub/cli'.

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

Related errors


AI-assisted analysis of lobehub/lobehub@10f24d7ade (2026-08-12). Data as JSON: /api/errors/7ea826b385bf9a78. Report an issue: GitHub.