Node + tsx "__name is not a function" 崩溃
Node + tsx "__name is not a function" 崩溃
适用范围
在以下情况使用此页面:
- 调试仅 Node 的开发脚本或监视模式失败
- 调查 Clawdbot 中的 tsx/esbuild 加载器崩溃
摘要
通过 Node 使用 tsx 运行 Clawdbot 在启动时失败:
[clawdbot] 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 后开始的(提交 2871657e,2026-01-06)。相同的运行时路径与 Bun 一起工作。
环境
- Node: v25.x(在 v25.3.0 上观察到)
- tsx: 4.21.0
- OS: macOS(在其他运行 Node 25 的平台上也可能重现)
重现(仅 Node)
# 在 repo 根目录中
node --version
pnpm install
node --import tsx src/entry.ts statusrepo 中的最小重现
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 路径),
clawdbot status和gateway:watch工作。
变通方法
- 将 Bun 用于开发脚本(当前的临时恢复)。
- 使用 Node + tsc watch,然后运行编译的输出:
pnpm exec tsc --watch --preserveWatchOutput node --watch dist/entry.js status - 在本地确认:
pnpm exec tsc -p tsconfig.json+node dist/entry.js status在 Node 25 上工作。 - 如果可能,在 TS 加载器中禁用 esbuild keepNames(防止
__name助手插入);tsx 目前不公开这一点。 - 使用
tsx测试 Node LTS(22/24),看看问题是否是 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 回归。
- 测试
tsx每夜版本或如果存在已知回归则固定到早期版本。 - 如果在 Node LTS 上重现,请使用
__name堆栈跟踪向上游提交最小重现。