`pnpm try` crashes the agent run with `require is not defined` (local dev / ESM)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 197
- Forks
- 51
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 94
Description
What's happening
Running the wizard from source with pnpm try (which is tsx bin.ts) crashes once the agent run starts, with require is not defined.
The culprit is getClaudeCodeExecutablePath() in src/lib/agent/agent-interface.ts. It uses require.resolve('@anthropic-ai/claude-agent-sdk') to find the bundled Claude Code CLI. Under tsx we're running native ESM, where there's no global require — so the call throws.
Why prod is fine (and this only bites local dev)
The published build is ESM (format: 'esm' in tsdown.config), but rolldown rewrites require.resolve into a working __require.resolve at build time. So real users were never broken — this is purely a pnpm try / raw-tsx thing where that build-time rewrite doesn't happen.
The fix
Make getClaudeCodeExecutablePath() work under both module systems: use require.resolve when require exists, and fall back to walking up from the entry script to find @anthropic-ai/claude-agent-sdk in a sibling node_modules when it doesn't.
A working version of exactly this fix already exists in #514 (it rode along with the WizardAmp visualizer). The plan is to pull it out of that PR and land it on its own, with a test, so it gets reviewed on its own merits — this issue tracks that.
Acceptance
-
pnpm try --install-dir=<path>reaches the agent run withoutrequire is not defined - Production (compiled) path still resolves the CLI correctly
- A test covers the ESM resolution fallback
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/lib/agent/agent-interface.ts at getClaudeCodeExecutablePath(), then inspect the working version in PR #514. Run pnpm try --install-dir= to reproduce the ESM failure and verify the production path still works. Add a test covering the ESM resolution fallback and confirm the agent run starts without require is not defined.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100