Next.js Discord

Discord Forum

Dynamic Server Usage

Unanswered
.dric posted this in #help-forum
Open in Discord
Hello.

Ever since I upgraded to the latest NextJS version, my app has been broken and hasn't been able to push to production.

I've been getting this error, dynamic server usage and it's been a pain in the behind.

Here's one dynamic server usage error that I got:

Error getting cookie: Error: Dynamic server usage: Route /explore couldn't be rendered statically because it used `cookies`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
    at m (.next/server/chunks/4447.js:12:42338)
    at d (.next/server/chunks/4474.js:10:31910)
    at Object.get (.next/server/app/(other)/auth/callback/route.js:1:3255)
    at e (.next/server/chunks/4474.js:10:347)
    at r (.next/server/chunks/4474.js:10:440)
    at Object.getItem (.next/server/chunks/4474.js:10:3097)
    at eX (.next/server/chunks/4474.js:6:20963)
    at tI._recoverAndRefresh (.next/server/chunks/4474.js:6:58838)
    at tI._initialize (.next/server/chunks/4474.js:6:37329)
    at <unknown> (.next/server/chunks/4474.js:6:36544) {
  description: "Route /explore couldn't be rendered statically because it used `cookies`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error",
  digest: 'DYNAMIC_SERVER_USAGE'
}


I've been trying to fix this for about a week to no avail.

All help would be nice. Thank you so much in advance.

7 Replies

@.dric hello man have u got a solution please ?
Yeah I fixed it a while back
Do you have some official docs to share or something please ?
I read that we may use
export const dynamic = 'force-dynamic';

But i don't know if it's the correct way to go ?

For my part I'm using cookies in server actions, to add cookies when fetching my api ...
yeah , i asked a question here
https://nextjs-forum.com/post/1450930551136583891
Do you think you can help please ?
Western paper wasp
cookies() (App Router): https://nextjs.org/docs/app/api-reference/functions/cookies

dynamic rendering (force-dynamic, no-store):
https://nextjs.org/docs/app/building-your-application/rendering/dynamic-rendering

Dynamic Server Usage error:
https://nextjs.org/docs/messages/dynamic-server-error

This is expected behavior. Using cookies() automatically makes the route dynamic, so it cannot be rendered statically. You need to explicitly specify dynamic rendering export const dynamic = 'force-dynamic', or use noStore() / cache: ‘no-store’ if the data must always be fresh.
Hello @Western paper wasp
Thank you for your response !