Appearance
Node + tsx 崩溃:"__name is not a function"
问题摘要
通过 Node + tsx 运行 OpenClaw 时,启动阶段报错:
[openclaw] Failed to start CLI: TypeError: __name is not a function
at createSubsystemLogger (.../src/logging/subsystem.ts:203:25)
at .../src/agents/auth-profiles/constants.ts:25:20此问题始于将开发脚本从 Bun 切换到 tsx(commit 2871657e,2026-01-06)。同一运行路径在 Bun 下正常工作。
环境信息
- Node:v25.x(已在 v25.3.0 复现)
- tsx:4.21.0
- OS:macOS(其他运行 Node 25 的平台也可能复现)
复现步骤(仅限 Node)
bash
# 在仓库根目录
node --version
pnpm install
node --import tsx src/entry.ts status仓库内最小复现
bash
node --import tsx scripts/repro/tsx-name-repro.tsNode 版本验证
- Node 25.3.0:失败
- Node 22.22.0(Homebrew
node@22):失败 - Node 24:尚未安装,需验证
原因分析
tsx使用 esbuild 转换 TS/ESM。esbuild 的keepNames会输出__name辅助函数,并用__name(...)包裹函数定义。- 崩溃表明
__name存在但在运行时不是函数,这意味着辅助函数在 Node 25 加载器路径中丢失或被覆盖。 - 其他使用 esbuild 的工具也曾报告类似的
__name辅助函数问题。
回归历史
2871657e(2026-01-06):脚本从 Bun 改为 tsx,使 Bun 变为可选依赖。- 改动之前(Bun 路径),
openclaw status和gateway:watch均正常工作。
临时绕过方案
使用 Bun 运行开发脚本(当前临时回退方案)。
使用 Node + tsc watch,然后运行编译产物:
bashpnpm exec tsc --watch --preserveWatchOutput node --watch openclaw.mjs status本地验证:
pnpm exec tsc -p tsconfig.json+node openclaw.mjs status在 Node 25 上可正常运行。如果 TS 加载器支持,禁用 esbuild 的 keepNames(防止插入
__name辅助函数);tsx 目前不暴露此选项。测试 Node LTS(22/24)+
tsx,确认是否为 Node 25 特有问题。
参考资料
- https://opennext.js.org/cloudflare/howtos/keep_names
- https://esbuild.github.io/api/#keep-names
- https://github.com/evanw/esbuild/issues/1031
后续步骤
- 在 Node 22/24 上复现,确认是否为 Node 25 回归。
- 测试
tsxnightly 版本,或锁定到早期版本(如存在已知回归)。 - 若在 Node LTS 上同样复现,向上游提交带
__name堆栈跟踪的最小复现。