Node + tsx 启动崩溃:__name is not a function

Node + tsx 启动崩溃:__name is not a function

本页记录一个在“使用 Node + tsx 直接运行 OpenClaw 源码”时可能遇到的启动崩溃现象,以及可用的绕过方案。

现象(错误信息)

启动阶段报错(核心特征:__name is not a function),示例:

TypeError: __name is not a function

复现方式(Node-only)

在 OpenClaw 源码仓库根目录:

node --version
pnpm install
node --import tsx src/entry.ts status

已观察到的环境(来自官方调试笔记)

  • Node:v25.x(示例:v25.3.0)
  • tsx:4.21.0
  • OS:macOS(其他可运行 Node 25 的平台也可能遇到)

可能原因(简述)

官方调试笔记的判断是:tsx 依赖 esbuild 转换时会插入 __name helper;该 helper 在某些 loader 路径下可能缺失或被覆盖,从而导致运行时崩溃。

绕过方案(优先级从高到低)

方案 1:用 tsc watch 编译后运行产物

pnpm exec tsc --watch --preserveWatchOutput
node --watch openclaw.mjs status

方案 2:直接编译一次再运行

pnpm exec tsc -p tsconfig.json
node openclaw.mjs status

方案 3:改用 Bun(如果你的开发流已使用 Bun)

如果你的开发脚本/工作流支持 Bun,优先用 Bun 路径来规避 tsx loader 的运行时差异。

下一步(建议验证)

  • 在 Node LTS(例如 22/24)上验证是否仍可复现
  • 若在 LTS 仍复现,建议用“最小复现脚本”向上游提交 issue

来源

素材来源:官方文档源 openclaw/docs/debug/node-issue.md(本页为中文化整理与操作入口聚合)。