Skip to content

[Windows] OPENCLAW_EXTENSION_API_PATH fallback paths missing Windows support #575

@jlin53882

Description

@jlin53882

Bug Description

The getExtensionApiImportSpecifiers() function in index.ts does not support Windows platform paths, causing memory-reflection and other features that depend on extensionAPI.js to fail on Windows.

Error Message

Error: Unable to load OpenClaw embedded runtime API. Set OPENCLAW_EXTENSION_API_PATH if runtime layout differs.
Attempts: openclaw/dist/extensionAPI.js: Cannot find module 'openclaw/dist/extensionAPI.js'
Require stack:
- C:\Users\admin\.openclaw\extensions\memory-lancedb-pro\index.ts | file:///C:/usr/lib/node_modules/openclaw/dist/extensionAPI.js

Root Cause

The getExtensionApiImportSpecifiers() function only checks Unix/macOS paths:

function getExtensionApiImportSpecifiers(): string[] {
  const envPath = process.env.OPENCLAW_EXTENSION_API_PATH?.trim();
  const specifiers: string[] = [];

  if (envPath) specifiers.push(toImportSpecifier(envPath));
  specifiers.push("openclaw/dist/extensionAPI.js");

  try {
    specifiers.push(toImportSpecifier(requireFromHere.resolve("openclaw/dist/extensionAPI.js")));
  } catch {
    // ignore resolve failures and continue fallback probing
  }

  specifiers.push(toImportSpecifier("/usr/lib/node_modules/openclaw/dist/extensionAPI.js"));
  specifiers.push(toImportSpecifier("/usr/local/lib/node_modules/openclaw/dist/extensionAPI.js"));
  // Missing: Windows npm global path (%APPDATA%\npm\node_modules\...)

  return [...new Set(specifiers.filter(Boolean))];
}

Missing Windows Paths

On Windows, npm global packages are typically installed to:

  • %APPDATA%\npm\node_modules\openclaw\dist\extensionAPI.js

Suggested Fix

Add Windows-specific fallback path using process.env.APPDATA:

// Windows npm global
const windowsNpmPath = path.join(process.env.APPDATA || '', 'npm', 'node_modules', 'openclaw', 'dist', 'extensionAPI.js');
specifiers.push(toImportSpecifier(windowsNpmPath));

Environment

  • OS: Windows
  • npm global path: C:\Users\{username}\AppData\Roaming\npm\node_modules\openclaw\dist\extensionAPI.js
  • OPENCLAW_EXTENSION_API_PATH: Currently required as workaround

Workaround

Manually set OPENCLAW_EXTENSION_API_PATH environment variable to:

%APPDATA%\npm\node_modules\openclaw\dist\extensionAPI.js

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions