Error library

Vercel FUNCTION_INVOCATION_FAILED (500)

Vercel returns FUNCTION_INVOCATION_FAILED (500) when the runtime crashes or the code throws an unhandled exception or rejection. Check the function logs for the real error, often a missing env var in production.

Cause: Uncaught exception, unhandled promise rejection, or a crashed runtime.

How to fix it

  1. Open the deployment's Logs tab and find the stack trace.
  2. Check production env vars are set (a missing one often throws at import time).
  3. Wrap handler logic in try/catch and return a proper error response.
  4. Reproduce locally with production env values.

Example

Illustrative example, not from a customer project.

- const client = new Stripe(process.env.STRIPE_SECRET_KEY!)
+ if (!process.env.STRIPE_SECRET_KEY) throw new Error('STRIPE_SECRET_KEY not set')
+ const client = new Stripe(process.env.STRIPE_SECRET_KEY)

FAQ

It works locally.

Production often lacks an env var or has a different runtime; check the logs.

Where are the logs?

In the Vercel dashboard under the deployment's Logs.

Get a $149 diagnosis See pricing Launching soon? The Launch Path gets you ready for $1,195 flat.

$149Get a $149 diagnosis