Used cookies/headers inside a function cached with unstable_cache Next.js Origin: On your device Last updated 5 Nov 2026

Next.js: Route used `cookies()` inside a function cached with `unstable_cache(...)`. Accessing Dynamic data sources inside a cache scope is not supported

A cached function reads request-specific data (cookies, headers), which would leak between users.

Exact message you may see used `cookies()` inside a function cached with `unstable_cache(...)`. Accessing Dynamic data sources inside a cache scope is not supportedused headers() inside a function cached with unstable_cacheAccessing Dynamic data sources inside a cache scope is not supportedRoute used cookies inside "use cache"
Seen on: Next.js React

Meaning

Read cookies()/headers() outside the cached function and pass the needed values as arguments (they become part of the cache key). Cached output must depend only on its arguments. The same rule applies to "use cache" functions.

Common causes

  • cookies()/headers() called in unstable_cache callback
  • Auth/user data read inside a cached helper
  • Search params accessed within the cache scope
  • Shared data function used both cached and uncached
  • Hidden dynamic access in a dependency

⚡ Quick fix

  1. const uid = (await cookies()).get("uid")?.value; const getData = unstable_cache(fn, [uid]) pass uid as an argument
  2. Move user-specific logic outside the cache
  3. Cache only public data

Detailed fix by platform

Next.js

  1. const getPosts = unstable_cache(async (uid: string) => db.posts(uid), ["posts"], { revalidate: 60 });

How to diagnose

  1. Source — cookies/headers inside cache?
  2. Args — Passed in?
  3. Data — User-specific?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Conflicting app and page file was found — Next.js: ⨯ Conflicting app and page file was found, please remove the conflicting files to continue: "pages/index.tsx" - "app/page.tsx" (Next.js)Conflicting app and p…cookies() should be awaited — Next.js 15: Route "/x" used `cookies().get('token')`. `cookies()` should be awaited before using its value (Next.js)cookies() should be a…Dynamic server usage — Error: Dynamic server usage: Route /x couldn't be rendered statically because it used `cookies` (React)Dynamic server usageFailed to set Next.js data cache, items over 2MB can not be cached — Next.js: Failed to set Next.js data cache for https://api.example.com/data, items over 2MB can not be cached (2437412 bytes) (Next.js)Failed to set Next.js…next build: fetch failed ECONNREFUSED (build-time API) — Next.js: Error occurred prerendering page "/blog" TypeError: fetch failed { cause: Error: connect ECONNREFUSED 127.0.0.1:3000 } (Next.js)next build: fetch fai…next build: JavaScript heap out of memory — Next.js: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory (during next build) (Next.js)next build: JavaScrip…Route used revalidatePath during render — Next.js: Error: Route /blog used "revalidatePath /blog" during render which is unsupported. It must happen outside of renders and cached functions (Next.js)Route used revalidate…Used cook…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.