{"record":{"id":"0bedbdd2f903b5c6","repo":"ruvnet/ruflo","slug":"could-not-find-repository-root-no-package-json-fo","errorCode":null,"errorMessage":"Could not find repository root (no package.json found)","messagePattern":"Could not find repository root \\(no package\\.json found\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ruflo/src/ruvocal/src/lib/server/findRepoRoot.ts","lineNumber":12,"sourceCode":"import { existsSync } from \"fs\";\nimport { join, dirname } from \"path\";\n\nexport function findRepoRoot(startPath: string): string {\n\tlet currentPath = startPath;\n\twhile (currentPath !== \"/\") {\n\t\tif (existsSync(join(currentPath, \"package.json\"))) {\n\t\t\treturn currentPath;\n\t\t}\n\t\tcurrentPath = dirname(currentPath);\n\t}\n\tthrow new Error(\"Could not find repository root (no package.json found)\");\n}\n","sourceCodeStart":1,"sourceCodeEnd":14,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/ruflo/src/ruvocal/src/lib/server/findRepoRoot.ts#L1-L14","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run from a directory inside the project that contains (or is under) a package.json.","If deploying bundled output, ship a package.json at the repo root or pass an explicit root instead of using findRepoRoot.","Pass an explicit startPath known to be under the project root rather than relying on cwd.","Replace the marker with one that exists in your layout (e.g. a .git dir) if package.json is intentionally absent."],"exampleFix":"// before\nconst root = findRepoRoot(process.cwd()); // from /tmp → throws\n\n// after\nconst root = findRepoRoot(require('path').resolve(__dirname));\n// or ensure a package.json exists at the project root before calling","handlingStrategy":"validation","validationCode":"function findRepoRootSafe(startPath: string): string | null {\n  let cur = startPath;\n  while (cur !== '/') { if (existsSync(join(cur, 'package.json'))) return cur; cur = dirname(cur); }\n  return null;\n}\nconst root = findRepoRootSafe(startPath);\nif (!root) throw new Error('Run from inside a project containing package.json');","typeGuard":"function hasRepoRoot(startPath: string): boolean { let cur = startPath; while (cur !== '/') { if (existsSync(join(cur, 'package.json'))) return true; cur = dirname(cur); } return false; }","tryCatchPattern":"try { return findRepoRoot(startPath); } catch (e) { if ((e as Error).message.startsWith('Could not find repository root')) return process.cwd(); throw e; }","preventionTips":["Call findRepoRoot with a path known to be under the project (e.g. __dirname), not an arbitrary cwd.","Ship a package.json at the repo root in bundled deployments.","Fall back to an explicit root rather than walking from /tmp."],"tags":["filesystem","path","repository","ruvocal"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}