PostHog / PostHog/wizard

`pnpm try` crashes the agent run with `require is not defined` (local dev / ESM)

Open
#611 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

agent-ready P0 wizard-pain
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 without require 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.