next.jserror-handlingruntime-errorunhandledclerk

Unhandled Runtime Error in NextJS, Clerk, and MongoDB project


My NextJs project was working fine as I was signed in. As soon as signed out, I faced this Unhandled Runtime Error: Error: Only plain objects, and a few built-ins, can be passed to Client Components from Server Components. Classes or null prototypes are not supported. PLEASE HELP!

Image of an error on browser

The strange thing is that the error is only occurring when I am trying to sign in from localhost:3000. When I tried opening localhost:3000/image. I successfully got the option to log in.

Project Structure

Problematic piece of the code

The problem is occurring somewhere around here, because I commented out the parts shown in the image, and I got the home page rendered. No Sign In option though.


Solution

  • AFAICT you are trying to serialize a class instance or null to JSON somewhere in your Next.js code, probably with JSON.stringify(), and this is not supported, as per what the error message says. And this occurs after a timeout expires.