Menu

Next.js 16: Fixing "cookies() can't be read inside 'use cache'" (and Caching Public Data Without It)
📰

Next.js 16: Fixing "cookies() can't be read inside 'use cache'" (and Caching Public Data Without It)

DEV Community: nextjs·Sushil·14 days ago
#NPl3PtdF
#devtonextjs#devto#dev#cache#next
Reading 0:00
15s threshold

You turn on Cache Components, add 'use cache' to a data function, and the build fails:

Error: Route "/broken": `cookies()` can't be read inside `"use cache"`. Read it outside the cached function and pass what you need as an argument. Learn more: https://nextjs.org/docs/messages/next-request-in-use-cache at h (lib/server-client.ts:6:29) at i (app/broken/page.tsx:7:24)

Enter fullscreen mode

Exit fullscreen mode

The confusing part is that your cached function might never call cookies() itself. In this example, the call is inside a helper that creates a "server client", the kind of cookie-aware factory that many auth and database SDKs ship for the App Router.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.