TencentCloud/TencentDB-Agent-Memory · error

runEmbeddedPiAgent not exported from dist/extensionAPI.js

Error message

runEmbeddedPiAgent not exported from dist/extensionAPI.js

What it means

After successfully importing dist/extensionAPI.js, loadRunEmbeddedPiAgent verifies that the module actually exports a runEmbeddedPiAgent function. If the export is missing or not a function it throws, indicating the installed/built module is stale or incompatible with the runner's expected API surface.

Source

Thrown at MemoryCore/src/utils/clean-context-runner.ts:146

    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)`);
    return mod.runEmbeddedPiAgent as RunEmbeddedPiAgentFn;
  })();

  _loadPromise.catch(() => { _loadPromise = null; });
  return _loadPromise;
}

/**
 * Pre-warm the embedded agent import. Call this during plugin init to avoid
 * the cold-start penalty on the first actual extraction run.
 * Returns immediately (fire-and-forget) — errors are swallowed.
 */
export function prewarmEmbeddedAgent(
  logger?: RunnerLogger,
  agentRuntime?: EmbeddedAgentRuntimeLike,
): void {

View on GitHub (pinned to 3efcd317b8)

Solutions

  1. Rebuild (`pnpm build`) the openclaw package so dist matches current sources
  2. Align versions: install the openclaw version the runner expects (check package.json/lockfile)
  3. Grep dist/extensionAPI.js for `runEmbeddedPiAgent` to confirm the export exists
  4. Clear cached module state — the failed promise is reset, so fixing the file and retrying works

Example fix

// before (extensionAPI.ts)
export { runEmbeddedPiAgent as runAgent }
// after
export { runEmbeddedPiAgent }
Defensive patterns

Strategy: validation

Validate before calling

const mod = await import(pathToFileURL(distPath).href);
if (typeof mod.runEmbeddedPiAgent !== 'function') throw new Error('incompatible openclaw build: runEmbeddedPiAgent missing');

Type guard

const hasRunEmbeddedPiAgent = (m: unknown): m is { runEmbeddedPiAgent: RunEmbeddedPiAgentFn } => typeof (m as any)?.runEmbeddedPiAgent === 'function';

Try / catch

try { const run = await loadRunEmbeddedPiAgent(logger); } catch (e) { if (/not exported/.test(e.message)) { logger.error('openclaw build/version mismatch; rebuild or pin the expected version'); } else throw e; }

Prevention

When it happens

Trigger: Loading the embedded agent when the built extensionAPI.js is from a different version that dropped/renamed runEmbeddedPiAgent, or a partial build produced an empty/incompatible module.

Common situations: Version mismatch between the runner (MemoryCore) and the installed openclaw package; stale dist/ from an older build after upgrading; tree-shaken or custom builds stripping the export.

Related errors


AI-assisted analysis of TencentCloud/TencentDB-Agent-Memory@3efcd317b8 (2026-09-01). Data as JSON: /api/errors/6c321926682e226d. Report an issue: GitHub.