Files
openclaw/docs/debug/node-issue.md

86 lines
2.8 KiB
Markdown
Raw Permalink Normal View History

2026-01-18 19:15:59 +00:00
---
summary: Node + tsx "__name is not a function" crash notes and workarounds
read_when:
- Debugging Node-only dev scripts or watch mode failures
2026-01-30 03:15:10 +01:00
- Investigating tsx/esbuild loader crashes in OpenClaw
title: "Node + tsx Crash"
2026-01-18 19:15:59 +00:00
---
2026-01-31 21:13:13 +09:00
# Node + tsx "\_\_name is not a function" crash
## Summary
2026-01-31 21:13:13 +09:00
2026-01-30 03:15:10 +01:00
Running OpenClaw via Node with `tsx` fails at startup with:
```
2026-01-30 03:15:10 +01:00
[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
```
This began after switching dev scripts from Bun to `tsx` (commit `2871657e`, 2026-01-06). The same runtime path worked with Bun.
## Environment
2026-01-31 21:13:13 +09:00
- Node: v25.x (observed on v25.3.0)
- tsx: 4.21.0
- OS: macOS (repro also likely on other platforms that run Node 25)
## Repro (Node-only)
2026-01-31 21:13:13 +09:00
```bash
# in repo root
node --version
pnpm install
node --import tsx src/entry.ts status
```
## Minimal repro in repo
2026-01-31 21:13:13 +09:00
```bash
node --import tsx scripts/repro/tsx-name-repro.ts
```
## Node version check
2026-01-31 21:13:13 +09:00
- Node 25.3.0: fails
- Node 22.22.0 (Homebrew `node@22`): fails
- Node 24: not installed here yet; needs verification
## Notes / hypothesis
2026-01-31 21:13:13 +09:00
- `tsx` uses esbuild to transform TS/ESM. esbuilds `keepNames` emits a `__name` helper and wraps function definitions with `__name(...)`.
- The crash indicates `__name` exists but is not a function at runtime, which implies the helper is missing or overwritten for this module in the Node 25 loader path.
- Similar `__name` helper issues have been reported in other esbuild consumers when the helper is missing or rewritten.
## Regression history
2026-01-31 21:13:13 +09:00
- `2871657e` (2026-01-06): scripts changed from Bun to tsx to make Bun optional.
2026-01-30 03:15:10 +01:00
- Before that (Bun path), `openclaw status` and `gateway:watch` worked.
## Workarounds
2026-01-31 21:13:13 +09:00
- Use Bun for dev scripts (current temporary revert).
- Use Node + tsc watch, then run compiled output:
```bash
pnpm exec tsc --watch --preserveWatchOutput
2026-01-30 03:15:10 +01:00
node --watch openclaw.mjs status
```
2026-01-30 03:15:10 +01:00
- Confirmed locally: `pnpm exec tsc -p tsconfig.json` + `node openclaw.mjs status` works on Node 25.
- Disable esbuild keepNames in the TS loader if possible (prevents `__name` helper insertion); tsx does not currently expose this.
- Test Node LTS (22/24) with `tsx` to see if the issue is Node 25specific.
## References
2026-01-31 21:13:13 +09:00
- [https://opennext.js.org/cloudflare/howtos/keep_names](https://opennext.js.org/cloudflare/howtos/keep_names)
- [https://esbuild.github.io/api/#keep-names](https://esbuild.github.io/api/#keep-names)
- [https://github.com/evanw/esbuild/issues/1031](https://github.com/evanw/esbuild/issues/1031)
## Next steps
2026-01-31 21:13:13 +09:00
- Repro on Node 22/24 to confirm Node 25 regression.
- Test `tsx` nightly or pin to earlier version if a known regression exists.
- If reproduces on Node LTS, file a minimal repro upstream with the `__name` stack trace.