Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

My Nuxt site on Vercel shows 500 FUNCTION_INVOCATION_FAILED

ErrorFUNCTION_INVOCATION_FAILED: Internal Server Error

Short answer

FUNCTION_INVOCATION_FAILED means the server function crashed while handling a request. Nuxt bundles pages and server routes into one function, so one thrown error can take down a page. Read the function log for the real error, then fix the code path, the environment variable or the legacy Nuxt 2 setup it points to.

  • Applies to Nuxt 3, Nuxt 4, Node.js 22, Vercel
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the project on Vercel, go to the Logs tab, filter to the failing path and read the first error line. That line is the cause. Everything below depends on it.

    # The same logs from a terminal, with the Vercel CLI
    npx vercel logs <your-deployment-url>
  2. 2Match what you see, then jump to its fix

    1. 1A stack trace in the function log pointing at your own file under server/ or at a page's data fetchAn error is thrown and nobody catches itFix
    2. 2The log shows undefined values or a failed connection that works locallyThe function runs with different settings than your machineFix
    3. 3package.json has nuxt 2.x and the project builds with nuxt buildA legacy Nuxt 2 project is running with server-side renderingFix

What does the error look like?

  • FUNCTION_INVOCATION_FAILED: Internal Server Error
  • Vercel deploy serverless function has crashed

Cause 1 of 3

An error is thrown and nobody catches it

1Check

Vercel lists a crashed runtime and an unhandled rejection or uncaught exception as the two reasons for this error. Find the route that logs the trace and read the code around that line.

# reproduce with the production build locally
npx nuxt build
node .output/server/index.mjs

2Fix

Wrap the failing call in try/catch, log the real error, and return a controlled response with an error status instead of letting the exception escape.

// server/api/items.get.ts
export default defineEventHandler(async () => {
  try {
    return await loadItems();
  } catch (err) {
    console.error('items failed:', err);
    throw createError({ statusCode: 502, statusMessage: 'Upstream failed' });
  }
});

3Verify

Request the route again. A handled failure now returns your status and the log shows your message instead of FUNCTION_INVOCATION_FAILED.

curl -i https://your-app.vercel.app/api/items

Confirmed by vercel.com

Did this fix it?

Cause 2 of 3

The function runs with different settings than your machine

1Check

Vercel tells you to verify the function's configuration, environment variables included. Compare the variables in Project Settings with your local .env.

npx vercel env ls

2Fix

Add the missing variable for the environment that is failing, then redeploy. A new deployment is needed for the change to apply.

npx vercel env add DATABASE_URL production
npx vercel --prod

3Verify

Open the page that crashed and confirm the Logs tab shows no new error.

npx vercel logs <your-deployment-url>

Confirmed by vercel.com

Did this fix it?

Cause 3 of 3

A legacy Nuxt 2 project is running with server-side rendering

1Check

The Nuxt team does not recommend deploying legacy Nuxt versions such as Nuxt 2 on Vercel except as static sites. Check which Nuxt version you have.

npm ls nuxt

2Fix

Either build a static site with nuxt generate, or upgrade through Nuxt Bridge or the Nuxt migration guide. Do not keep SSR on Nuxt 2 on Vercel.

# package.json
"scripts": { "build": "nuxt generate" }

3Verify

Redeploy and open the site. Pages are served as static files, with no server function to crash.

curl -I https://your-app.vercel.app/

Confirmed by vercel.com

Did this fix it?

How do I stop it coming back?

  • Wrap external calls (database, third-party APIs) in try/catch and return a clear error response.
  • Run the production build locally before pushing, so crashes show on your machine first.
  • Add every environment variable to the right Vercel environment when you add it to .env.
  • Keep Nuxt on a current major version if you need server-side rendering.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.