500 server error when deploy my next js sanity blog to netlify

Hello developers. I am having an issue deploying my next js (v13.4.19) blog project with Sanity (next-sanity v5.4.6).

After I deploy and visit the given blog url, it shows a 500 server error and these messages on the console :

“Failed to load resource: the server responded with a status of 500 ()” and
“A client-side exception has occurred, see here for more info: Client-side Exception Occurred | Next.js
Q @ main-aa5775583063cd73.js:1”

I keep getting these errors, even though the build succeeded, and when i visit /studio it shows my sanity content studio with no problem, also i have no problem when i try to build it with vs code and host it on my machine.

note: i have tried to deploy my blog several time and each time it fails in the first build attempt with this error:

and in the second time it gets deployed successfully but with 500 server error when i visit the blog url, i am sure that i have set all my env vars to netlify correctly but still getting this issue. So is there any way to resolve this problem?

Which website is this about? I assume it’s most likely related to: Server.edge not defined Error on nextJS SSR functions cause site to return 500 Errors