500: INTERNAL_SERVER_ERROR / FUNCTION_INVOCATION_FAILED on Vercel

On this page

Short answer

Your server code crashed while it was handling the request. Vercel lists two causes: the runtime process crashed, or the code threw "an unhandled rejection/uncaught exception." The page only tells you that it crashed. The cause is in the function's runtime log, so read that before you change any code.

Find a fix pack

Checklists and prompts for Supabase security, Stripe payments and deploys. Each pack is $24, or $49 for all three.

The exact error you'll see

The visitor sees a Vercel error page. This text is from a page quoted in a vercel/next.js GitHub issue. The ID: line that follows differs for each request.

This Serverless Function has crashed.

Your connection is working correctly.

Vercel is working correctly.

500: INTERNAL_SERVER_ERROR
Code: FUNCTION_INVOCATION_FAILED

Source: https://github.com/vercel/next.js/issues/40065 (opens in a new tab)

Vercel's error reference lists the code with status 500:

FUNCTION_INVOCATION_FAILED

Source: https://vercel.com/docs/errors/FUNCTION_INVOCATION_FAILED (opens in a new tab)

Applies to

  • Vercel Functions on the Node.js runtime: Next.js API routes, route handlers and server rendering, plus /api functions in Vite apps made with v0, Lovable, Bolt or Cursor
  • Node.js versions Vercel currently offers: 26.x (default), 24.x and 22.x, set in Project Settings or engines.node in package.json
  • Settings involved: Environment Variables, the Node.js Version setting, and runtime logs

Why it happens

  • An exception nobody caught. Vercel's troubleshooting steps say to look for "any unhandled exceptions within the function code."
  • Missing or wrong configuration. Vercel says to check "the function configuration... including any environment variables." A variable that is undefined at run time can make the code throw.
  • An environment change that never reached the live deployment. Vercel says variable changes "are not applied to previous deployments, they only apply to new deployments."
  • A Node version mismatch. engines.node in package.json overrides the version selected in Project Settings.

How to fix it, step by step

  1. Reproduce the error once and note the time.
  2. Open the project's Logs and filter by HTTP status code 500 and by Request Path. Vercel supports both filters, plus deployment and environment. Open the matching request and read the first error and its stack trace.
  3. If the stack trace names a missing value, open Settings → Environment Variables, confirm the exact name, and confirm it is set for the right environment (Production or Preview). Then redeploy, because a saved change alone doesn't reach the running deployment.
  4. If it's a module or syntax error, check the Node version. In Settings → Build and Deployment → Node.js Version, compare it with engines.node in package.json. To confirm what actually ran, Vercel suggests logging process.version inside the function.
  5. If it's an error from your own code or an upstream call, wrap that call so the function returns a clear 4xx or 5xx response instead of crashing. Vercel's steps suggest a try/catch block. Don't swallow the error silently.
  6. To test without deploying, run vercel dev. Vercel says it replicates "the Vercel deployment environment locally." For Next.js, Vercel says next dev already covers Functions, so prefer that.
  7. Redeploy and repeat the exact failing request, not just the homepage.

What the docs don't spell out

  • On Hobby, the evidence expires fast. Vercel keeps runtime logs for "1 hour" on Hobby and "1 day" on Pro. Reproduce the error, then read the log right away. (Runtime logs (opens in a new tab))
  • Huge logs get cut off. Each request can log up to 1 MB and 256 log lines. If you dump large objects, the line with the real error may be missing. Log the error message and stack instead. (Runtime logs (opens in a new tab))
  • Node minor versions can differ. Vercel says "the exact minor version can differ between the build and the function runtime." A build that passes doesn't prove the function runs on the same Node release. (Node.js versions (opens in a new tab))

How to check it worked

  • The original failing request now returns the expected status, not 500.
  • The Logs view, filtered to that path and status 500, shows no new entries after the redeploy.
  • If you changed variables, the deployment you're testing was created after the change.

Sources

  1. https://vercel.com/docs/errors/FUNCTION_INVOCATION_FAILED (opens in a new tab): definition, 500 status, possible causes, troubleshooting steps
  2. https://github.com/vercel/next.js/issues/40065 (opens in a new tab): exact text of the visitor-facing crash page
  3. https://vercel.com/docs/logs/runtime (opens in a new tab): log filters, retention by plan, per-request log limits
  4. https://vercel.com/docs/environment-variables (opens in a new tab): changes apply only to new deployments; per-environment scoping
  5. https://vercel.com/docs/functions/runtimes/node-js/node-js-versions (opens in a new tab): available versions, settings path, engines.node override, process.version
  6. https://vercel.com/docs/cli/dev (opens in a new tab): vercel dev purpose, and next dev for Next.js

Tool to consider: Better Stack.

Find a fix pack

Checklists and prompts for Supabase security, Stripe payments and deploys. Each pack is $24, or $49 for all three.