T
TanStack6d ago
continuing-cyan

ClientOnly not working, error still raised on server side

Hey! I have some code which I want to only run on the client side (100ms live - https://www.npmjs.com/package/@100mslive/react-sdk). I am currently getting this error on the server:
Uncaught Error: Switched to client rendering because the server rendering errored:

The requested module 'eventemitter2' does not provide an export named 'EventEmitter2'
...
Uncaught Error: Switched to client rendering because the server rendering errored:

The requested module 'eventemitter2' does not provide an export named 'EventEmitter2'
...
I have tried to wrap the code in ClientOnly, but the error continues to happen
return (
<ClientOnly>
<HMSRoomProvider>...</HMSRoomProvider>
</ClientOnly>
)
return (
<ClientOnly>
<HMSRoomProvider>...</HMSRoomProvider>
</ClientOnly>
)
The only solution that I have found is to disable ssr for the entire route (ssr: false). Is there any way that I can have ssr so the loader runs on the server (rather than on the client w/server function), but not have the server include the 100ms part of the code in it's build? I have also tried changing values in the vite.config.ts but didn't have any success 😔 Thanks for your help!!
2 Replies
unwilling-turquoise
unwilling-turquoise5d ago
continuing-cyan
continuing-cyanOP5d ago
Ahh this is great! Thank you @Manuel Schiller 🙇‍♂️

Did you find this page helpful?