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_hooks
How 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
AppRouter type from a separate file that doesn't import any server code (e.g., src/server/api/types.ts that re-exports only the type)
- Add
serverExternalPackages: ['postgres'] to next.config.js
- Add
import "server-only" to server files as a guard
- Some combination of the above
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 buildfails with 6 "Module not found" errors (fs,net,tls,perf_hooks). Next.js16.1.7builds successfully — the regression is specific to16.2.0.The root cause is that
16.2.0follows 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:
How to reproduce
pnpm create t3-app@latest(select tRPC + Drizzle + PostgreSQL)package.json, change"next"to"16.2.0"pnpm install && pnpm buildNote: 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
Possible solutions
AppRoutertype from a separate file that doesn't import any server code (e.g.,src/server/api/types.tsthat re-exports only the type)serverExternalPackages: ['postgres']tonext.config.jsimport "server-only"to server files as a guard