TanStackT
TanStackโ€ข5mo agoโ€ข
3 replies
popular-magenta

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'
...


I have tried to wrap the code in ClientOnly, but the error continues to happen
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!!
Was this page helpful?