Fix: Vercel Deployment Failed - Common Causes and Solutions
Quick Answer
Fix Vercel deployment failures caused by build errors, environment variables, serverless function limits, and dependency issues with step-by-step solutions.
The Error
Your Vercel deployment fails with one of these messages in the build log:
Error: Command "npm run build" exited with 1Error: Serverless Function has exceeded the unzipped maximum size of 250 MBError: No Output Directory named "out" found after the Build completedThe deployment shows a red status in the Vercel dashboard, and your site isn’t updated.
Why This Happens
Vercel runs your build command in a serverless environment with specific constraints. The build has limited memory, specific Node.js versions, and strict size limits for serverless functions. Unlike your local machine, Vercel starts each build from a clean state (though it caches node_modules), so environment differences often surface during deployment.
Fix 1: Fix Build Command Errors
The most common failure. Check your build output in the Vercel dashboard under Deployments > [failed deployment] > Build Logs.
Common issues:
# TypeScript errors that you ignored locally
Type error: Property 'x' does not exist on type 'y'
# ESLint errors treated as warnings locally but errors in CI
error Unexpected console statement no-consoleYour next.config.js or framework config might treat warnings as errors in production:
// next.config.js
module.exports = {
eslint: {
ignoreDuringBuilds: true, // Skip ESLint during build
},
typescript: {
ignoreBuildErrors: true, // Skip type checking (not recommended)
},
};A better approach is to fix the actual errors. Run the same build command locally:
npm run buildPro Tip: Add
"build:check": "tsc --noEmit && eslint . && next build"to your package.json and run it locally before pushing. This catches exactly what Vercel will catch.
Fix 2: Configure Environment Variables
Environment variables set in your local .env file don’t exist on Vercel. Add them in the Vercel dashboard under Settings > Environment Variables:
DATABASE_URL=postgresql://...
NEXT_PUBLIC_API_URL=https://api.example.com
SECRET_KEY=your-secretKey points:
- Variables prefixed with
NEXT_PUBLIC_are exposed to the browser in Next.js - Variables without the prefix are only available server-side
- Set different values for Production, Preview, and Development environments
- Vercel automatically sets
VERCEL,VERCEL_ENV,VERCEL_URL, and other system variables
If your build accesses environment variables at build time, they must be present during the build. Runtime-only variables work for serverless functions but not for static generation.
Check if a variable is missing:
// This crashes the build if DB_URL is undefined
const db = new Database(process.env.DB_URL); // undefined
// Guard against missing variables
if (!process.env.DB_URL) {
throw new Error('DB_URL environment variable is required');
}Fix 3: Fix Serverless Function Size Limits
Vercel limits serverless functions to 250 MB unzipped. If your API routes or server-side rendered pages bundle too many dependencies, you hit this limit:
Error: Serverless Function has exceeded the unzipped maximum size of 250 MBReduce function size:
// next.config.js
module.exports = {
experimental: {
outputFileTracingExcludes: {
'/api/*': ['./node_modules/@swc/core-linux-x64-gnu'],
},
},
};Move heavy dependencies to Edge Functions where appropriate:
// pages/api/light-endpoint.js
export const config = {
runtime: 'edge', // Much smaller size limit applies differently
};Check which dependencies are bloating your functions:
npx @next/bundle-analyzerCommon culprits: aws-sdk (use @aws-sdk/client-s3 instead), sharp (Vercel provides it), prisma (use the data proxy).
Fix 4: Set the Correct Node.js Version
Vercel uses a specific Node.js version that might differ from your local setup. Specify it in your project settings or package.json:
{
"engines": {
"node": "20.x"
}
}Or in Vercel project settings under Settings > General > Node.js Version.
Mismatched versions cause issues with:
- Native modules compiled for a different Node.js version
- Syntax features not available in the target version
- npm/yarn lockfile incompatibilities
Check the build log for the Node.js version being used:
Installing Node.js 18.xFix 5: Fix Monorepo Root Directory
If your project is in a monorepo subdirectory, Vercel needs to know where to find it:
monorepo/
├── packages/
│ ├── web/ ← Your Vercel project
│ ├── api/
│ └── shared/
├── package.json
└── turbo.jsonSet the Root Directory in Vercel: Settings > General > Root Directory to packages/web.
For Turborepo or Nx monorepos, configure the build command:
# Vercel build command
cd ../.. && npx turbo run build --filter=webCommon Mistake: Setting the root directory but forgetting that dependencies from the monorepo root
node_modulesaren’t available. UseinstallCommandoverride:cd ../.. && npm install && cd packages/web.
Common monorepo issues:
- Shared packages not being built before the web app
- Workspace protocol (
workspace:*) not resolved during Vercel install - Missing
.npmrcor.yarnrc.ymlconfiguration
Fix 6: Fix Edge Function Issues
Edge Functions have stricter limits than regular serverless functions:
Error: Edge Function has hit the maximum size limit (1 MB)Edge Functions can’t use Node.js APIs like fs, path, or child_process. They run in the V8 runtime:
// This fails in Edge Functions
import fs from 'fs'; // Not available
// Use Web APIs instead
export const config = { runtime: 'edge' };
export default async function handler(request) {
const data = await fetch('https://api.example.com/data');
return new Response(JSON.stringify(await data.json()));
}If your function needs Node.js APIs, use the default serverless runtime instead of edge.
Fix 7: Fix Dependency Installation Failures
Vercel installs dependencies based on your lockfile. If it’s corrupted or outdated:
npm ERR! ERESOLVE unable to resolve dependency treeFix steps:
# Regenerate lockfile locally
rm -rf node_modules package-lock.json
npm install
git add package-lock.json
git commit -m "Regenerate lockfile"
git pushFor peer dependency conflicts, either resolve them or use the --legacy-peer-deps flag:
{
"scripts": {
"vercel-install": "npm install --legacy-peer-deps"
}
}Set the install command in Vercel settings to npm run vercel-install.
If using private packages, add an NPM token:
# Vercel environment variable
NPM_TOKEN=npm_xxxxxCreate .npmrc in your project:
//registry.npmjs.org/:_authToken=${NPM_TOKEN}Fix 8: Fix Framework Detection
Vercel auto-detects your framework (Next.js, Astro, Vite, etc.) and sets build commands accordingly. If detection fails:
Error: No framework detectedOverride in vercel.json:
{
"framework": "nextjs",
"buildCommand": "npm run build",
"outputDirectory": ".next"
}Common framework settings:
| Framework | Build Command | Output Directory |
|---|---|---|
| Next.js | next build | .next |
| Astro | astro build | dist |
| Vite/React | vite build | dist |
| CRA | react-scripts build | build |
| Nuxt | nuxt build | .output |
If your output directory doesn’t match what Vercel expects, the deployment succeeds but shows a 404:
{
"outputDirectory": "dist"
}Still Not Working?
Check build memory limits. Vercel’s free tier has limited build memory. If your build runs out of memory, optimize it or upgrade your plan. Look for
JavaScript heap out of memoryin build logs.Review Vercel’s system status. Intermittent build failures might be platform issues.
Test with
vercel buildlocally. Install the Vercel CLI (npm i -g vercel) and runvercel buildto reproduce the deployment environment locally.Check API route configuration. API routes must export a default function. Missing exports cause silent deployment failures.
Look for large static assets. Images, videos, or data files in your public directory count toward deployment size limits. Use external CDNs for large assets.
Verify Next.js configuration. Invalid
next.config.jsoptions can cause builds to fail without clear error messages. Test with a minimal config.
Solo developer based in Japan. Every solution is cross-referenced with official documentation and tested before publishing.
Was this article helpful?
Related Articles
Fix: Heroku H10 App Crashed Error
Fix the Heroku H10 App Crashed error by fixing your Procfile, PORT binding, missing dependencies, and build scripts with step-by-step solutions.
Fix: ASP.NET 500 Internal Server Error
Fix ASP.NET 500 Internal Server Error by enabling developer exception pages, fixing DI registration, connection strings, and middleware configuration.
Fix: Celery Task Not Received or Not Executing
Fix Celery tasks not being received or executed by resolving broker connections, autodiscovery issues, task name mismatches, and worker configuration.
Fix: Elasticsearch Cluster Health Red Status
Fix Elasticsearch cluster health red status by resolving unassigned shards, disk watermark issues, node failures, and shard allocation problems.