fix(tokenless): replace __dirname with import.meta.dirname for ESM compatibility#878
fix(tokenless): replace __dirname with import.meta.dirname for ESM compatibility#878shiloong wants to merge 1 commit into
Conversation
Code Review:
|
| 检查项 | 结果 |
|---|---|
是否有其他 __dirname 残留 |
✅ 无,仅此两处 |
| 其他 adapter 是否受影响 | ✅ 无,仅 openclaw 是 TS adapter |
| 运行时崩溃风险 | ✅ 无,fallback 兜底 + Node 22+ 支持 import.meta.dirname |
| 向后兼容性 | ✅ 无破坏,Node 22+ 为 OpenClaw 最低版本 |
…law plugin OpenClaw 2026.6.5 (5181e4f) fails to load tokenless plugin at registration with ReferenceError: __dirname is not defined. The openclaw adapter package.json declares type:module (ESM) and tsconfig outputs Node16 module format, which produces ESM import syntax in dist/index.js. However loadToolCategories() used the CJS global __dirname to resolve tool_categories.json paths — this variable does not exist in ESM modules. Replace the two __dirname references with import.meta.dirname (Node 20.11+; OpenClaw 2026.6.5 runs on Node 22+). Other openclaw plugins (sec-core, ws-ckpt, agent-memory) were checked and have no bare __dirname usage — no similar bug exists elsewhere. Signed-off-by: Shile Zhang <shile.zhang@linux.alibaba.com>
fixed, thx! |
Code Review — PR #878结论:✅ Approve 根因分析清晰:ESM 模块中 建议(非阻塞):
|
Description
Related Issue
fixes # openclaw plugins install errors
Type of Change
Scope
cosh(copilot-shell)sec-core(agent-sec-core)skill(os-skills)sight(agentsight)tokenless(tokenless)ckpt(ws-ckpt)memory(agent-memory)anolisa(anolisa-cli)Checklist
cosh: Lint passes, type check passes, and tests passsec-core(Rust):cargo clippy -- -D warningsandcargo fmt --checkpasssec-core(Python): Ruff format and pytest passskill: Skill directory structure is valid and shell scripts pass syntax checksight:cargo clippy -- -D warningsandcargo fmt --checkpasstokenless:cargo clippy -- -D warningsandcargo fmt --checkpassmemory(Linux only):cargo clippy --all-targets -- -D warnings,cargo fmt --check, andcargo testpassanolisa:cargo clippy --all-targets --locked -- -D warnings,cargo fmt --all --check, andcargo test --lockedpasspackage-lock.json/Cargo.lock)Testing
Additional Notes