Demo, all content is generated
Question

Server action works locally, production just says 'An error occurred in the Server Components render'

Solved · 615 views · asked by astrid_n · edited

Admin page, button calls a server action that creates an invite. Locally fine. On Vercel the toast shows:

Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.

How do I even debug this when it hides the message?

What I’ve tried

Added console.log in the action, can't find where it goes. Redeployed with a clean cache.

Comment
Check the function logs in the Vercel dashboard, the real error is there. tom_brewer · edited

3 answers

Marked as helpful by the asker
mei_lin · edited

The real message is in your server logs, it's only hidden from the browser. Vercel dashboard → your project → Logs, filter on the time you clicked. Your console.log output is there too. The digest in the browser error matches a line in the logs if there are many.

My blind guess for "works locally, fails on Vercel, admin action": you use SUPABASE_SERVICE_ROLE_KEY in that action and it's only in .env.local, not in Vercel's env vars (or only set for Preview).

Comment
Logs said supabaseKey is required. Service role key was in .env.local only. Added it in Vercel for Production, redeployed, works. Didn't know Logs existed, honestly. astrid_n · edited
Double check it has no NEXT_PUBLIC_ prefix while you're there. That key must never reach the browser. amir_h · edited
gus_fullstack · edited

For next time: wrap the action body in try/catch and return { error: 'something readable' } instead of throwing. You decide what the user sees, and you log the real error server-side.

Comment
chidi_eze · edited

Also note: that error text is generic. Anything thrown in a server component or action in production looks like this, so don't read too much into the wording. The log line is what matters.

Comment