Vercel 500 FUNCTION_INVOCATION_FAILED: How to Fix It
Your Vercel site shows 500: INTERNAL_SERVER_ERROR, Code: FUNCTION_INVOCATION_FAILED? Roll back, read the runtime logs, and fix the crash behind it.
Your site was fine yesterday, and now Vercel shows a bare error page: 500: INTERNAL_SERVER_ERROR, then Code: FUNCTION_INVOCATION_FAILED and an ID. The build passed and the deployment says Ready. This error means one of your Vercel Functions (an API route or a server-rendered page) crashed while answering the request. The fix is almost always in your code or your project settings, and the runtime logs tell you which.
This guide follows Vercel's docs for the FUNCTION_INVOCATION_FAILED error, runtime logs, troubleshooting functions, debugging production 500 errors and Instant Rollback, with real cases from the Vercel community forum.
What the error looks like
Visitors see Vercel's own error page instead of your app:
500: INTERNAL_SERVER_ERROR
Code: FUNCTION_INVOCATION_FAILED
ID: ...
Vercel's docs give the full message as FUNCTION_INVOCATION_FAILED: Internal Server Error with status 500, and list two possible causes:
- the runtime process (Node.js, Bun, Python and so on) crashed;
- Node.js or Bun threw an unhandled rejection or uncaught exception.
So the page tells you only that the function died, not why. If the home page is server-rendered, the whole site is down. If only one API route fails, the site loads but a form or a button stops working.
Before you dig in, take ten seconds to rule out a platform problem on the live Vercel status page. If Vercel is fine, it's your function. A 504 with FUNCTION_INVOCATION_TIMEOUT is a different problem (a function that runs too long); this guide to Vercel error codes covers it.
Step 1: Get the site back with Instant Rollback
If the 500 started with your latest deploy, you don't have to debug with the site down. Vercel's Instant Rollback points your domains back to an earlier production deployment right away:
- Open the project's overview page.
- On the production deployment tile, click Instant Rollback.
- Select the deployment to roll back to and click Continue.
- Check the domains listed, then click Confirm Rollback.
From the terminal, the same thing is vercel rollback <deployment-url-or-id>.
Two things to know. Hobby projects can roll back only to the deployment just before the current one; Pro and Enterprise can pick any deployment that was once on a production domain. And a rollback brings back the previous build: environment variables you change in the settings afterwards don't reach it. If the crash comes from outside the code, like a database that stopped answering, a rollback won't fix it.
After a rollback, Vercel turns off auto-assignment of production domains, so new pushes won't go live until you undo it. That's in Step 4.
Step 2: Find the real error in the logs
The error page hides the cause. The runtime logs show it.
- On the dashboard, select the project.
- Open Logs in the sidebar.
- Filter by Status Code
500, or set Level to Error. Vercel marks requests with a 5xx status in red. - Click a failing request. The bottom panel shows the log messages in order, including the stack trace.
Look at the Request Path too. If every failing request is /, your home page is crashing. If it's one route like /api/checkout, the rest of the site is fine.
From the terminal, in a linked project:
vercel logs --environment production --query 'level:error' --since 1h
Move fast on the Hobby plan: Vercel keeps runtime logs for 1 hour there, 1 day on Pro. If the failing requests are older than that, open the page again to create a fresh one.
Build logs won't help here. They cover the build, and this error happens when a request comes in.
Step 3: Fix the cause
Match the message in the logs to one of these.
A value from process.env is undefined
Vercel's troubleshooting page puts it plainly: variables in your local .env file or your shell don't exist in a deployment. Code like new Client(process.env.DATABASE_URL) then throws on the first request.
- On the dashboard, select the project and open Environment Variables in the sidebar.
- Enter the Name and Value of each variable your code reads, select every environment that needs it, such as Production and Preview, and click Save.
- Redeploy. Changes apply only to new deployments.
To compare, vercel env pull downloads the project's Development variables into a local file. If your app talks to Supabase, a missing key often shows up as supabaseUrl is required in the logs.
Cannot find module
A message like Cannot find module '/var/task/node_modules/...' means the function can't load a package. In one community thread, the log added Did you forget to add it to "dependencies" in package.json? before the process exited. Check that:
- the package is in
dependencies, not onlydevDependenciesor installed globally on your machine; - it doesn't compile native code. Vercel's docs use
bcryptas the example and suggestbcryptjs, which needs no native build. If you deploy withvercel deploy --prebuilt, runvercel buildon Linux with an x64 CPU, since a binary built on macOS or Windows won't run.
In that thread, a Vercel team member said they had shipped a fix, and two posters confirmed a redeploy cleared the error. If your setup looks right, redeploying is a cheap test.
ENOENT or EROFS
ENOENT: no such file or directory or EROFS: read-only file system means the code reads a file that isn't in the function's bundle, or writes to disk. A Vercel Function can only write to /tmp, which isn't shared between instances and doesn't last. Write temporary files there, keep data in a storage service, and if your code builds a file path at runtime, add the file to the bundle explicitly as Vercel's runtime docs describe.
Unhandled rejection or uncaught exception
The log shows Unhandled Rejection: or a plain stack trace, often ending with Node.js process exited with exit status. In another thread, an Express app logged Unhandled Rejection: SocketError: other side closed and the page showed exactly this 500.
Vercel's advice is to wrap the function's work in try/catch, so one failed call returns an error you control instead of killing the process:
export async function GET() {
try {
const data = await loadData();
return Response.json(data);
} catch (error) {
console.error(error);
return Response.json({ error: "Something went wrong" }, { status: 500 });
}
}
If the failing call is to a database or an external API and the logs show ECONNRESET or TypeError: fetch failed, the other service closed the connection. Vercel's troubleshooting page suggests a timeout and a retry for requests that are safe to repeat, and checking whether that service only accepts certain IP addresses.
Step 4: Test on a preview, then ship
Vercel's guide to production 500 errors tests the fix before it reaches visitors:
vercel deploy # preview deployment
vercel curl /api/failing-route --deployment <preview-url>
vercel deploy --prod
vercel logs requests --environment production --query 'httpStatus:500' --since 5m
If the last command finds no requests, the fix works. Then open the site in a private window and check the status line:
curl -sI https://example.com | head -1
You want HTTP/2 200, not HTTP/2 500.
If you rolled back in Step 1, undo it, or your next pushes won't go live: on the project's overview page, click Manage on the production deployment tile, select the new deployment, and click Confirm. From the terminal, vercel promote <deployment-url-or-id> does the same.
Pingbuddy catches this automatically
When a server-rendered page crashes, the page itself answers with a 500, and Pingbuddy's uptime check treats any status of 400 or above as a failure. It opens your address every 5 minutes on the Free plan (up to 50 sites) or every minute on Pro and Agency, and after two failed checks in a row it alerts you on Telegram or by email that the site shows an error page instead of your app. If only an API route crashes, add that route's URL as its own site, since the check opens only the address you give it.
To see where your site stands right now, run a free checkup.
FAQ
- What does FUNCTION_INVOCATION_FAILED mean on Vercel?
- One of your Vercel Functions crashed while handling the request, so Vercel answered with a 500. Vercel's error docs name two causes: the runtime process (Node.js, Bun, Python and so on) crashed, or the code threw an unhandled rejection or uncaught exception. The real error message is in the project's runtime logs.
- Why does my app work locally but crash with FUNCTION_INVOCATION_FAILED on Vercel?
- A deployed function runs on Linux with a read-only filesystem, only the files Vercel bundled, and the environment variables from your project settings. Vercel's troubleshooting page lists the usual gaps: a variable that's only in your local .env file, a package with native code, a file missing from the bundle, or code that writes to disk outside /tmp.
- Is FUNCTION_INVOCATION_FAILED a Vercel outage?
- Usually not. The code means your own function failed. Check the Vercel status page to rule out an incident, then open Logs in your project and filter by status 500 to see the error your code threw.
- How is FUNCTION_INVOCATION_FAILED different from FUNCTION_INVOCATION_TIMEOUT?
- FUNCTION_INVOCATION_FAILED is a 500: the function crashed or threw an error it didn't handle. FUNCTION_INVOCATION_TIMEOUT is a 504: the function ran longer than it's allowed to, often while waiting on a slow database or API. Vercel's troubleshooting page sends timeouts to its guide on debugging slow functions.