Skip to content

fix(pkg): add source condition to exports for Turbopack workspace resolution#51

Merged
jonmatum merged 1 commit intomainfrom
claude/fix-exports-source-condition
Apr 17, 2026
Merged

fix(pkg): add source condition to exports for Turbopack workspace resolution#51
jonmatum merged 1 commit intomainfrom
claude/fix-exports-source-condition

Conversation

@jonmatum
Copy link
Copy Markdown
Owner

Summary

Adds "source": "./src/<path>.ts" to every export in package.json.

Root cause: Turbopack lazily resolves workspace packages through their dist/ files. When @jonmatum/next-shell/auth was the very first subpath compiled in a fresh session (e.g. /dashboard as the initial route after a server redirect), Turbopack failed to resolve it with Module not found. Navigating to any other route in the (shell) group first would warm the cache and fix it — confirming a lazy-compilation race specific to the first module boundary crossing.

Fix: The source condition tells Turbopack to compile from TypeScript source directly when the package is a workspace symlink. This is the standard pattern for pnpm monorepo library packages. The condition is ignored by all other consumers (Node require, webpack, standard ESM bundlers).

Verification

pnpm lint      ✓
pnpm typecheck ✓
pnpm test      ✓ 508/508
curl /dashboard as first route → 200 (previously 500)

…orkspace resolution

Without a source condition, Turbopack lazily compiles workspace packages
through their dist/ files. When @jonmatum/next-shell/auth was the first
subpath resolved in a fresh Turbopack session (e.g. /dashboard as the
initial route), the module couldn't be resolved — likely a race in
Turbopack's symlink + package exports resolution during the first
compilation pass.

Adding "source": "./src/<path>.ts" to every export entry tells Turbopack
to compile from TypeScript source directly when the package is resolved
as a workspace symlink. This is the standard pattern for pnpm monorepo
library packages with Next.js 15 / Turbopack.

The source condition is ignored by non-Turbopack consumers (Node CJS
require, standard ESM bundlers) since they don't recognize it, so
published behavior is unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@jonmatumdev jonmatumdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All checks passed. AI review found no issues. Auto-approved.

@jonmatum jonmatum merged commit 08c16a2 into main Apr 17, 2026
1 check passed
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.

2 participants