Skip to content

fix(dev): pin turbopack root and randomize the dev server port - #11

Merged
EliRobinson merged 2 commits into
mainfrom
fix/turbopack-root-warning
Aug 27, 2026
Merged

EliRobinson merged 2 commits into
mainfrom
fix/turbopack-root-warning

Conversation

@EliRobinson

@EliRobinson EliRobinson commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Pins turbopack.root in next.config.ts so Next.js stops inferring the workspace root from sibling lockfiles (a stray one in the home dir, or another worktree under .claude/worktrees/*), which fired the "inferred your workspace root" warning on every pnpm dev.
  • Drops the dev script's -p flag entirely (next dev --turbopack, no port arg). next dev already reads PORT from the environment natively, so:
    • Plain pnpm dev falls back to Next's own 3000-and-increment behavior.
    • PORT=3010 pnpm dev still forces a specific port.
    • .claude/launch.json's autoPort: true (added here) can assign a genuinely free port itself and hand it in via PORT — this only works when the script doesn't hardcode -p, which the previous -p ${PORT:-3000} did.
  • Moves the E2E server off port 3000 too (playwright.config.ts's PORT → 3417). That's a separate next start instance (pnpm test:e2epnpm build && pnpm start), unrelated to pnpm dev, but 3000 is the port most likely to already be held by someone's dev server. playwright.config.ts is now the single source for that port — dropped CI's redundant PLAYWRIGHT_BASE_URL override so it can't drift out of sync.

Why not -p 0?

The issue originally proposed next dev --turbopack -p 0 (OS-assigned random port). I tried that first, but it breaks .claude/launch.json's autoPort integration: autoPort works by picking a free port itself and injecting it via the PORT env var when spawning the dev command — a hardcoded -p 0 overrides that and the two disagree about which port the server is actually on. Dropping -p entirely (confirmed next dev reads PORT on its own) is what makes both paths — manual and autoPort-driven — agree.

Test plan

  • pnpm type-check, pnpm lint, pnpm format:check, pnpm test (pre-push hook, all green)
  • pnpm dev no longer prints the workspace-root inference warning, verified with sibling worktree lockfiles present
  • PORT=4321 next dev --turbopack binds to exactly 4321 with no -p flag present, confirming the env-var path autoPort relies on
  • PORT=3417 next start binds to exactly 3417 the same way
  • pnpm build && pnpm exec playwright test --project=chromium — all 4 E2E specs pass against the server on port 3417

🤖 Generated with Claude Code

EliRobinson and others added 2 commits August 27, 2026 11:22
A sibling lockfile above or beside the project (a stray one in the home
directory, or another worktree under .claude/worktrees/* carrying its own
pnpm-lock.yaml) makes Next.js infer the wrong workspace root and print the
warning on every dev server start. Pinning turbopack.root explicitly removes
the inference.

Fixes #10

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
next dev already reads the PORT env var natively, so dropping the -p flag
entirely lets Next fall back to its own 3000-and-increment behavior for
plain `pnpm dev`, while `.claude/launch.json`'s `autoPort: true` can assign
a genuinely free port by setting PORT before spawning it — that only works
when nothing hardcodes `-p`, which the previous `-p ${PORT:-3000}` did.

Moves the E2E server (a separate `next start` instance, unrelated to `pnpm
dev`) off 3000 too, since that's the port most likely to already be held by
someone's dev server. playwright.config.ts is the single source for it now;
CI's redundant PLAYWRIGHT_BASE_URL override is dropped so it can't drift.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@EliRobinson EliRobinson changed the title fix(dev): pin turbopack.root to silence workspace-root inference warning fix(dev): pin turbopack root and randomize the dev server port Aug 27, 2026
@EliRobinson
EliRobinson merged commit 708cfeb into main Aug 27, 2026
3 checks passed
@EliRobinson
EliRobinson deleted the fix/turbopack-root-warning branch August 27, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant