TencentCloud/TencentDB-Agent-Memory · error
Unable to resolve OpenClaw root. Set OPENCLAW_ROOT or run `p
Error message
Unable to resolve OpenClaw root. Set OPENCLAW_ROOT or run `pnpm build`.
What it means
resolveOpenClawRoot locates the openclaw package root by walking up from well-known starting points (and OPENCLAW_ROOT). If no candidate directory contains the openclaw package, the runner cannot locate dist/extensionAPI.js and throws, telling you to set OPENCLAW_ROOT explicitly or build the package with `pnpm build`.
Source
Thrown at MemoryCore/src/utils/clean-context-runner.ts:130
dir = parent;
}
}
function resolveOpenClawRoot(): string {
if (_rootCache) return _rootCache;
const override = getEnv("OPENCLAW_ROOT")?.trim();
if (override) { _rootCache = override; return override; }
const candidates = new Set<string>();
if (process.argv[1]) candidates.add(path.dirname(process.argv[1]));
candidates.add(process.cwd());
try { candidates.add(path.dirname(fileURLToPath(import.meta.url))); } catch { /* ignore */ }
for (const start of candidates) {
const found = findPackageRoot(start, "openclaw");
if (found) { _rootCache = found; return found; }
}
throw new Error("Unable to resolve OpenClaw root. Set OPENCLAW_ROOT or run `pnpm build`.");
}
let _loadPromise: Promise<RunEmbeddedPiAgentFn> | null = null;
function loadRunEmbeddedPiAgent(logger?: RunnerLogger): Promise<RunEmbeddedPiAgentFn> {
if (_loadPromise) return _loadPromise;
_loadPromise = (async () => {
const t0 = Date.now();
const distPath = path.join(resolveOpenClawRoot(), "dist", "extensionAPI.js");
if (!fsSync.existsSync(distPath)) {
throw new Error(`Missing core module at ${distPath}. Run \`pnpm build\` or install the official package.`);
}
const mod = await import(pathToFileURL(distPath).href);
if (typeof mod.runEmbeddedPiAgent !== "function") {
throw new Error("runEmbeddedPiAgent not exported from dist/extensionAPI.js");
}
logger?.info(`${TAG} loadRunEmbeddedPiAgent: dist/ import OK (${Date.now() - t0}ms)`);View on GitHub (pinned to 3efcd317b8)
Solutions
- Run `pnpm build` in the openclaw package so the package root with dist/ exists
- Set OPENCLAW_ROOT to the absolute path of the openclaw package root
- Install the official openclaw package if it is missing from node_modules
- Verify findPackageRoot's candidate start dirs include your runtime location (e.g. when bundled)
Example fix
// before OPENCLAW_ROOT=./openclaw/src // after OPENCLAW_ROOT=/abs/path/to/openclaw # dir containing package.json with name "openclaw"
Defensive patterns
Strategy: fallback
Validate before calling
const root = process.env.OPENCLAW_ROOT ?? path.resolve('node_modules/openclaw');
if (!fsSync.existsSync(path.join(root, 'package.json'))) { logger.error('openclaw root missing; run pnpm build or set OPENCLAW_ROOT'); } Try / catch
try { const run = await loadRunEmbeddedPiAgent(logger); } catch (e) { if (/Unable to resolve OpenClaw root/.test(e.message)) { logger.error('Set OPENCLAW_ROOT or run pnpm build'); process.exitCode = 1; } else throw e; } Prevention
- Set OPENCLAW_ROOT explicitly in deployment env/config
- Always build the openclaw package in CI before running services
- Verify the package root exists in your container/entrypoint startup checks
When it happens
Trigger: Calling the clean-context runner (directly or via loadRunEmbeddedPiAgent/distPath) when the openclaw package is not installed, is installed but unbuilt, or OPENCLAW_ROOT points to the wrong directory.
Common situations: Fresh checkout without running `pnpm build`; running from a bundled/standalone context where import.meta.url candidates don't resolve into the package; monorepo layout changes moving the package root; OPENCLAW_ROOT set to src instead of the package dir.
Related errors
AI-assisted analysis of TencentCloud/TencentDB-Agent-Memory@3efcd317b8 (2026-09-01).
Data as JSON: /api/errors/9e144523188b8152.
Report an issue: GitHub.