| name | vercel-deploy |
| description | Vercel deployment workflows for Next.js — preview deployments, environment variables, branch configuration, log troubleshooting, and production rollbacks. Use when deploying to Vercel, debugging failed builds, or configuring deployment settings. |
Vercel Deploy (Next.js)
Vercel deployment management for Next.js projects.
Deployment Flow
git push origin main
└─ Vercel: Production Deploy
└─ Build → Deploy → Ready (auto-assigns domain)
git push origin feature-branch
└─ Vercel: Preview Deploy
└─ Build → Deploy → Ready (auto-generates preview URL)
└─ Comment on PR with preview link
Project Configuration
vercel.json
{
"framework": "nextjs",
"buildCommand": "npm run build",
"outputDirectory": ".next",
"installCommand": "npm ci",
"regions": ["hnd1"],
"headers": [
{
"source": "/(.*)",
"headers": [
{ "key": "X-Frame-Options", "value": "DENY" },
{ "key": "X-Content-Type-Options", "value": "nosniff" },
{ "key": "Referrer-Policy", "value": "strict-origin-when-cross-origin" }
]
}
]
}
Environment Variables
DATABASE_URL=...
AUTH_SECRET=...
DATABASE_URL=..._preview
NEXT_PUBLIC_API_URL=https://staging-api.example.com
DATABASE_URL=postgres://localhost:5432/dev
Best Practices:
- Production secrets → Vercel Dashboard (never in code)
NEXT_PUBLIC_* prefix for client-side env vars
- Use Vercel Environment Variable Groups for shared vars across projects
- Never commit
.env files (only .env.example)
Branch Configuration
Production Branch
Set in Vercel Dashboard: Project → Settings → Git → Production Branch
Production Branch: main
Preview Deployments
- Every push to non-production branches creates a preview
- Preview URLs:
project-name-git-branch-name-xxxxx.vercel.app
- Preview branches can be limited in Settings → Git → Ignored Branches
Ignored Branches:
- dependabot/**
- renovate/**
- docs/**
Build Troubleshooting
Common Build Failures
| Error | Likely Cause | Fix |
|---|
Module not found | Missing dependency | npm ci locally, check lockfile |
Build exceeded memory limit | Too many parallel builds, memory leak | Reduce parallel tasks, check for memory leaks |
Command "npm run build" exited with 1 | TypeScript/ESLint errors | Run npm run lint + npx tsc --noEmit locally |
Function Invocation Failed (Serverless) | Lambda timeout or memory | Increase function memory/maxDuration in vercel.json |
Error: ENOENT: no such file or directory | Build artifact not found | Check outputDirectory in vercel.json |
Debug Locally
npm run build
npx next build
npm run start
vercel build --prod
npx serve .vercel/output/static
Logs & Monitoring
vercel logs <deployment-url>
vercel logs --tail
Speed Insights & Analytics
Enable in Vercel Dashboard:
- Speed Insights → Core Web Vitals (LCP, CLS, INP) per route
- Web Analytics → Page views, top pages, traffic sources
Rollback
vercel rollback
vercel rollback <deployment-id>
Checklist