Serverless Function has exceeded the unzipped maximum size of 250 MB

On this page

Short answer

One of your functions is bigger than Vercel's 250 MB limit once it's unpacked. Turn on the bundle report to see which files are in it, then exclude the ones it doesn't need. Use excludeFiles in vercel.json, or outputFileTracingExcludes for Next.js. If the function really needs the space, check whether your project can use large functions.

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 build fails with this line. Vercel quotes it in the Functions skill it publishes in its vercel-plugin repo:

Serverless Function has exceeded the unzipped maximum size of 250 MB

Source: https://github.com/vercel/vercel-plugin/blob/main/skills/vercel-functions/SKILL.md (opens in a new tab)

The limit applies to the uncompressed function bundle, not to your repo or source folder.

Applies to

  • Vercel Functions on the standard limit: 250 MB uncompressed, or 500 MB for Python
  • Next.js server routes and API routes, including apps built with v0 or Cursor
  • Settings involved: vercel.json functions config, next.config.js tracing options, and project environment variables

Why it happens

  • The limit counts more than your code. Vercel says the 250 MB maximum is "including layers which are automatically used depending on runtimes."
  • Heavy dependencies. Vercel names packages that ship binaries, such as Puppeteer with its bundled Chromium, and machine learning libraries. "Duplicate copies of the same package also add size."
  • Static assets traced into the function. "Images, videos, or large JSON files that server code imports or reads are packaged with the function."
  • Imports with variable paths. A path built at runtime "can make the bundler include every file in a directory."
  • Next.js tracing. During next build, Next.js uses @vercel/nft to "statically analyze import, require, and fs usage to determine all files that a page might load."

How to fix it, step by step

  1. In Settings → Environment Variables, add VERCEL_ANALYZE_BUILD_OUTPUT with the value 1 and redeploy. Vercel says the build logs then "list each function's uncompressed size and its largest files."
  2. Work down the largest files. Run npm ls <package> to see why a package is installed and npm dedupe to remove duplicates. Move images, videos and large JSON to the public directory or external storage, and use static import paths.
  3. If you're not on Next.js, exclude files the function doesn't need in vercel.json. This is Vercel's example. It keeps public and test out of every function under api:
{
  "functions": {
    "api/**": {
      "excludeFiles": "{public,test}/**"
    }
  }
}
  1. On Next.js, includeFiles and excludeFiles aren't supported. Use outputFileTracingExcludes in next.config.js instead. The keys are route globs and the values are glob patterns resolved from the project root. This is part of the Next.js example:
module.exports = {
  outputFileTracingExcludes: {
    '/api/*': ['src/temp/**/*', 'public/large-logs/**/*'],
  },
}

Swap in the paths your report flagged. Next.js says to keep patterns "as narrow as possible to avoid oversized traces (avoid **/* at the repo root)."

  1. If the files are all needed, look at large functions (beta). They allow uncompressed bundles "up to 5 GB" on Node.js, Bun and Python, and they "require fluid compute with Active CPU enabled." New projects are eligible by default. Existing projects opt in with the VERCEL_SUPPORT_LARGE_FUNCTIONS environment variable, then redeploy.
  2. Redeploy and watch the build get past the size check.

What the docs don't spell out

  • Excluding a file the function reads breaks it at run time, not at build time. Vercel's file guide explains how to include files a function reads while it runs. After trimming, test every route that reads files from disk. (Using files in functions (opens in a new tab))
  • Next.js trace options only touch server traces. Fully static pages and Edge Runtime routes aren't affected, so excluding paths for them won't shrink anything. (Next.js output (opens in a new tab))
  • The large-functions variable works both ways. Vercel's skill says it "always takes precedence over the project default, in both directions," and only functions over 250 MB use the large-function path. (Vercel Functions skill (opens in a new tab))

How to check it worked

  • The new deployment builds without the 250 MB error.
  • With VERCEL_ANALYZE_BUILD_OUTPUT=1 still set, the build log shows the function under the limit.
  • Routes that read templates, data files or binaries still work on the live deployment.

Sources

  1. https://github.com/vercel/vercel-plugin/blob/main/skills/vercel-functions/SKILL.md (opens in a new tab): exact build error, large-functions variable precedence
  2. https://vercel.com/docs/functions/limitations (opens in a new tab): 250 MB and 500 MB limits including layers, common causes, VERCEL_ANALYZE_BUILD_OUTPUT, npm ls/npm dedupe, excludeFiles example, large functions requirements and opt-in
  3. https://vercel.com/docs/project-configuration/vercel-json (opens in a new tab): includeFiles/excludeFiles not supported in Next.js
  4. https://nextjs.org/docs/app/api-reference/config/next-config-js/output (opens in a new tab): @vercel/nft tracing, outputFileTracingExcludes example, narrow patterns, static and Edge routes unaffected
  5. https://vercel.com/kb/guide/how-can-i-use-files-in-serverless-functions (opens in a new tab): including files a function reads at run time

Tool to consider: Vercel.

Find a fix pack

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