ruvnet/ruflo · error · Error

Could not find repository root (no package.json found)

Error message

Could not find repository root (no package.json found)

What it means

Thrown by findRepoRoot after it walks from startPath up the dirname chain to '/' without finding a package.json in any ancestor. The function uses package.json as the repository-root marker, so absence anywhere along the path means 'not inside a Node project'.

Source

Thrown at ruflo/src/ruvocal/src/lib/server/findRepoRoot.ts:12

import { existsSync } from "fs";
import { join, dirname } from "path";

export function findRepoRoot(startPath: string): string {
	let currentPath = startPath;
	while (currentPath !== "/") {
		if (existsSync(join(currentPath, "package.json"))) {
			return currentPath;
		}
		currentPath = dirname(currentPath);
	}
	throw new Error("Could not find repository root (no package.json found)");
}

View on GitHub (pinned to 6b01dc5a68)

Solutions

  1. Run from a directory inside the project that contains (or is under) a package.json.
  2. If deploying bundled output, ship a package.json at the repo root or pass an explicit root instead of using findRepoRoot.
  3. Pass an explicit startPath known to be under the project root rather than relying on cwd.
  4. Replace the marker with one that exists in your layout (e.g. a .git dir) if package.json is intentionally absent.

Example fix

// before
const root = findRepoRoot(process.cwd()); // from /tmp → throws

// after
const root = findRepoRoot(require('path').resolve(__dirname));
// or ensure a package.json exists at the project root before calling
Defensive patterns

Strategy: validation

Validate before calling

function findRepoRootSafe(startPath: string): string | null {
  let cur = startPath;
  while (cur !== '/') { if (existsSync(join(cur, 'package.json'))) return cur; cur = dirname(cur); }
  return null;
}
const root = findRepoRootSafe(startPath);
if (!root) throw new Error('Run from inside a project containing package.json');

Type guard

function hasRepoRoot(startPath: string): boolean { let cur = startPath; while (cur !== '/') { if (existsSync(join(cur, 'package.json'))) return true; cur = dirname(cur); } return false; }

Try / catch

try { return findRepoRoot(startPath); } catch (e) { if ((e as Error).message.startsWith('Could not find repository root')) return process.cwd(); throw e; }

Prevention

When it happens

Trigger: Calling findRepoRoot with a startPath outside any package.json tree: a path under /tmp, /var, the filesystem root, or a directory whose node project was deleted. Also if startPath is already '/' or a path with no ancestors containing package.json.

Common situations: Running the tool from /tmp or another scratch dir; a packaged/bundled deployment where the source tree (and its package.json) is not on disk; startPath derived from os.tmpdir() or a CI workspace that was not checked out; a monorepo where the nearest package.json is above a boundary the walker does handle but the cwd was set below a freshly created subdir without one.

Related errors


AI-assisted analysis of ruvnet/ruflo@6b01dc5a68 (2026-08-12). Data as JSON: /api/errors/0bedbdd2f903b5c6. Report an issue: GitHub.