bug: Server-only modules leak into client bundle with Next.js 16.2.0
Author: linditCreated Mar 19, 2026Updated Jun 22, 2026
Describe the bug
When using create-t3-app (v7.40.0, with tRPC + Drizzle + PostgreSQL) as a starter and upgrading Next.js to 16.2.0, next build fails with 6 "Module not found" errors (fs, net, tls, perf_hooks). Next.js 16.1.7 builds successfully — the regression is specific to 16.2.0.
The root cause is that 16.2.0 follows the module graph for type-only imports in "use client" files, pulling server-only code into the client bundle.
The import chain causing the leak:
src/trpc/react.tsx ("use client")
→ import { type AppRouter } from "~/server/api/root"
→ import { createCallerFactory, createTRPCRouter } from "~/server/api/trpc"
→ import { db } from "~/server/db"
→ import postgres from "postgres" // ← uses fs, net, tls, perf_hooksHow to reproduce
pnpm create t3-app@latest(select tRPC + Drizzle + PostgreSQL)- In
package.json, change"next"to"16.2.0" - Run
pnpm install && pnpm build - Build fails with:
Module not found: Can't resolve 'fs' Module not found: Can't resolve 'net' Module not found: Can't resolve 'tls' Module not found: Can't resolve 'perf_hooks'
Note: The same project builds successfully with Next.js 16.1.7.
Expected behavior
The build should succeed. Type-only imports (import { type AppRouter }) should not cause the bundler to follow the server module graph from a client component.
Environment
- create-t3-app: v7.40.0
- Next.js: 16.2.0 (breaks) / 16.1.7 (works)
- Node.js: v22
- Package manager: pnpm
Possible solutions
- Export the
AppRoutertype from a separate file that doesn't import any server code (e.g.,src/server/api/types.tsthat re-exports only the type) - Add
serverExternalPackages: ['postgres']tonext.config.js - Add
import "server-only"to server files as a guard - Some combination of the above
Source: t3-oss/create-t3-app