NextJS DynamicServerError with Cookies, Headers, and nextUrl.searchParams
Answered
Briquet Griffon Vendéen posted this in #help-forum
Briquet Griffon VendéenOP
I've been building a Blog engine tool for a while now. I got it to work, and everything was perfect. Until I ran
I've tried everything Google seems to say, including adding
The codebase is open-sourced: https://github.com/incogiscool/atom and the instructions to host it locally is in the README. I would love some help because I've been working on this issue for a few days with no results.
Thanks in advance for any responses!
npm run build and tried to host it in Vercel. It now shows three error messages, with the same error code DynamicServerError. Here are the three errors that occur on build:Dynamic server usage: Page couldn't be rendered statically because it used 'nextUrl.searchParams'Dynamic server usage: Page couldn't be rendered statically because it used 'cookies'Dynamic server usage: Page couldn't be rendered statically because it used 'headers'I've tried everything Google seems to say, including adding
export const dynamic = 'force-dynamic', but nothing seems to work.The codebase is open-sourced: https://github.com/incogiscool/atom and the instructions to host it locally is in the README. I would love some help because I've been working on this issue for a few days with no results.
Thanks in advance for any responses!
Answered by Briquet Griffon Vendéen
Hey, turns out the headers, cookies, and searchParams should always be outside of a try/catch statement on the server.
1 Reply
Briquet Griffon VendéenOP
Hey, turns out the headers, cookies, and searchParams should always be outside of a try/catch statement on the server.
Answer