← Debugging Guides

阅读中文版本

Vercel — serverless function exceeds size limit

Vercel build fails because a serverless function bundle exceeds the 250 MB uncompressed size limit, often from large dependencies or missing edge configuration.

intermediatedebuggingvercelbuild

Symptoms

  • Error: Function size exceeded 250MB limit
  • Build succeeds locally but fails on Vercel
  • The function includes large native modules or fonts

Possible causes

  • A large dependency like puppeteer or sharp is bundled into the function
  • The function imports the entire library instead of tree-shakeable subpaths
  • Node modules are not excluded via vercel.json

Diagnosis steps

Check the function bundle size

vercel inspect <deployment-url> --logs

Interpretation

The build log shows the uncompressed size of each function.

Identify large dependencies

du -sh node_modules/* | sort -rh | head -20

Interpretation

The largest directories are likely the culprits.

Root cause

Vercel enforces a 250 MB uncompressed limit on serverless function bundles; large dependencies inflate the bundle beyond this limit and the deployment is rejected.

Fix

Use edge functions for lightweight logic, move heavy deps to an external API, use includeFiles/excludeFiles in vercel.json, or switch to a smaller alternative library.

Verify the fix

Deploy and confirm the build succeeds; verify the function responds correctly in production.

Symptom walkthrough

Vercel build fails because a serverless function bundle exceeds the 250 MB uncompressed size limit, often from large dependencies or missing edge configuration. The error appears in production but may not surface in local development because the conditions that trigger it depend on the deployment environment or runtime configuration. Understanding the full symptom set helps distinguish this issue from similar errors.

Diagnosis in practice

Follow the diagnosis steps in the frontmatter to isolate the cause. Each step includes a command and an interpretation of the output. The goal is to narrow down whether the issue is in the configuration, the runtime, or the application code. Reproduce the error in a minimal setup before applying a fix.

Root cause

Vercel enforces a 250 MB uncompressed limit on serverless function bundles; large dependencies inflate the bundle beyond this limit and the deployment is rejected.

Fix

Use edge functions for lightweight logic, move heavy deps to an external API, use includeFiles/excludeFiles in vercel.json, or switch to a smaller alternative library. After applying the fix, monitor the system to confirm the error does not recur under load or in different environments.

Verification

Deploy and confirm the build succeeds; verify the function responds correctly in production. If the verification passes, the fix is confirmed; if not, re-examine the diagnosis steps for missed contributing factors.

Diagnostic commands

Run these commands to reproduce and diagnose the issue:

vercel inspect <deployment-url> --logs
du -sh node_modules/* | sort -rh | head -20