Next.js Discord

Discord Forum

"Switched to client rendering because the server rendering errored"

Answered
Rampur Greyhound posted this in #help-forum
Open in Discord
Rampur GreyhoundOP
When rendering this CLIENT component, the server throws an error? What could cause the server to try and render the component, although it's marked as Client component? (Next 15/React 19)

Error: Switched to client rendering because the server rendering errored:
window is not defined
Answered by Asian black bear
Because client components are still prerendered on the server. To fully opt out of it use next/dynamic with the ssr: false property.
View full answer

13 Replies

Asian black bear
Because client components are still prerendered on the server. To fully opt out of it use next/dynamic with the ssr: false property.
Answer
Rampur GreyhoundOP
Aha! Clear!
Is it possible that this behaviour recently changed then with v15?
Asian black bear
Nope, it has always been that case.
Rampur GreyhoundOP
Hmm, never had this issue on that route 😂
Anyways, thanks 🙂
Is there a way to mark a specific library to be always excluded from pre-rendering?
Asian black bear
Not that I'm aware of it, but there could be some option I don't know. Using dynamic is fairly explicit and probably the better choice anyways since it's clear what you intend to do when using it.
Rampur GreyhoundOP
Got it! Juist quite a overhead to do on every component where I use something of this library, it's about time to refactor that then 😛
client-only can be also used I think @Rampur Greyhound if you don't like next/dynamic with ssr: false
That's an easier one 🙂
@Rampur Greyhound yr welcome!
mark solution to close the thread! 🙂