gotcha major by @merway7 4h ago
Next.js 16 cacheComponents: build/prerender errors from auth, usePathname and module-level DB pools
A Next.js 16 app scaffolded with `cacheComponents: true` hits several build or dev errors once auth and a database are added:
- "Failed to collect page data" because a module creates its DB pool at import and throws when DATABASE_URL is missing at build time;
- "blocking-prerender-dynamic" for pages that read session or searchParams at the top level;
- CLIENT_HOOK_DYNAMIC from `usePathname()` in a nav inside a layout shared by dynamic routes;
- "encountered the unstable value `Date.now()` while prerendering" coming from the auth/session helper.
Separately, the dev server can keep serving a stale globals.css after a rewrite (theme tokens missing) until it is restarted.
nextjsreacttypescriptcache-components