Next.js Discord

Discord Forum

Error while using NextRequest url

Answered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
I'm trying to send a GET req to my API route with searchParams doing :

const { searchParams } = new URL(request.url) const url = searchParams.get("url")

but I'm getting the error 'Page with dynamic = "error" couldn't be rendered statically because it used request.url' with code NEXT_STATIC_GEN_BAILOUT
Answered by Ray
Using the Request object with the GET method will cause the page dynamic rendering
View full answer

17 Replies

Answer
@Sun bear I'm trying to send a GET req to my API route with searchParams doing : ` const { searchParams } = new URL(request.url) const url = searchParams.get("url")` but I'm getting the error 'Page with `dynamic = "error"` couldn't be rendered statically because it used `request.url`' with code NEXT_STATIC_GEN_BAILOUT
and you have export dynamic = "error" on that page which will force static rendering and cache the data of a layout or page by causing an error if any components use dynamic functions or uncached data
Sun bearOP
I don't set this up, shouldnt it be automatically set to 'auto' ?
you dont have export dynamic = "error" on any page?
@Ray you dont have export dynamic = "error" on any page?
Sun bearOP
nope, I'm fetching in a useEffect of a client side component, can it come from there ?
no i don't think so
Sun bearOP
ah after forcing it to rend dynamically I got a better log : had ouput: "export" set in next.config.js
yes was going to ask you
Sun bearOP
I find it hard to find docs on that
what does it do ?
it will render the site to plain html
so you can put it to cdn easily
but will lose all the server function
and ty for the quick answers!
please mark solution if you problem has been solved 😀