Next.js Discord

Discord Forum

"Switched to client rendering because the server rendering errored"

Unanswered
Rampur Greyhound posted this in #help-forum
Open in Discord
Avatar
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
Image

12 Replies

Avatar
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.
Avatar
Rampur GreyhoundOP
Aha! Clear!
Is it possible that this behaviour recently changed then with v15?
Avatar
Asian black bear
Nope, it has always been that case.
Avatar
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?
Avatar
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.
Avatar
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 😛
Avatar
client-only can be also used I think @Rampur Greyhound if you don't like next/dynamic with ssr: false
Avatar
Rampur GreyhoundOP
Oeh, thanks for the tip!
That's an easier one 🙂