| name | vercel-deployment |
| description | Deploy Next.js and React applications to Vercel — project setup, environment variables, edge functions, build troubleshooting, preview deployments, monorepo configuration. NOT for AWS/GCP/Azure deployment, self-hosted solutions, or Cloudflare Pages. |
| allowed-tools | Read,Write,Edit,Bash(npm:*,npx:*,vercel:*) |
| metadata | {"category":"DevOps & Site Reliability","tags":["devops","automation","web","react"],"pairs-with":[{"skill":"nextjs-app-router-expert","reason":"Vercel is optimized for Next.js deployment with native App Router feature support"},{"skill":"devops-automator","reason":"Vercel deployment automation integrates with broader CI/CD pipeline workflows"},{"skill":"github-actions-pipeline-builder","reason":"Vercel preview deployments trigger from GitHub Actions PR workflows"}]} |
Vercel Deployment
This skill helps you deploy and configure Next.js applications on Vercel following best practices.
Quick Deploy Checklist
Environment Variables
Setting Variables
Vercel Dashboard (Recommended for secrets):
- Project Settings → Environment Variables
- Add variable with appropriate scope:
- Production: Only production deployments
- Preview: PR and branch previews
- Development: Local
vercel dev
Via CLI:
vercel env add VARIABLE_NAME production
vercel env pull .env.local
Variable Naming
DATABASE_URL=
SESSION_SECRET=
ANTHROPIC_API_KEY=
NEXT_PUBLIC_APP_URL=
NEXT_PUBLIC_ANALYTICS_ID=
Size Limits
| Context | Limit |
|---|
| Total per deployment | 64 KB |
| Edge Functions | 5 KB per variable |
| Single variable | 64 KB max |
Required Variables for This Project
SESSION_SECRET=your-32-char-minimum-secret-here
ANTHROPIC_API_KEY=sk-ant-api...
DATABASE_URL=file:./data/app.db
VAPID_PUBLIC_KEY=
VAPID_PRIVATE_KEY=
VAPID_SUBJECT=mailto:admin@example.com
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
APPLE_CLIENT_ID=
APPLE_CLIENT_SECRET=
vercel.json Configuration
{
"buildCommand": "npm run build",
"framework": "nextjs",
"regions": ["iad1"],
"headers": [
{
"source": "/api/(.*)",
"headers": [
{ "key": "Cache-Control", "value": "no-store, must-revalidate" }
]
},
{
"source": "/(.*)",
"headers": [
{ "key": "X-Content-Type-Options", "value": "nosniff" },
{
TypeScript Configuration (New in 2025)
import { defineConfig } from '@vercel/config';
export default defineConfig({
regions: ['iad1'],
headers: async () => [
{
source: '/api/:path*',
headers: [
{ key: 'Cache-Control', value: 'no-store' },
],
},
],
redirects: async () => [
{
source: '/old',
destination: '/new',
permanent: true,
},
],
});
Edge Functions
When to Use Edge
Good for:
- Authentication/authorization
- A/B testing
- Geolocation-based content
- Request/response transforms
- Simple, fast operations
Not suitable for:
- Database connections (use serverless instead)
- Long-running operations
- Large dependencies
Edge Function Example
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export const config = {
matcher: ['/api/:path*', '/protected/:path*'],
};
export function middleware(request: NextRequest) {
const token = request.cookies.get('session')?.value;
if (!token && request.nextUrl.pathname.startsWith('/protected')) {
return NextResponse.redirect(new URL('/login', request.url));
}
const response = NextResponse.next();
response.headers.set('X-Request-Id', crypto.randomUUID());
return response;
}
Edge Runtime in API Routes
export const runtime = 'edge';
export async function GET(request: Request) {
return Response.json({ timestamp: Date.now() });
}
Build Configuration
package.json Scripts
{
"scripts": {
"build": "next build",
"postbuild": "npm run db:generate"
}
}
Build Environment
{
"engines": {
"node": "20.x"
}
}
Build Output
npm run build
ANALYZE=true npm run build
Database Considerations
SQLite on Vercel
SQLite with better-sqlite3 works in Vercel's serverless functions, but:
- Filesystem is read-only except
/tmp
- Data doesn't persist between invocations
- Not suitable for production data storage
Production Database Options
-
Turso (SQLite edge database)
import { createClient } from '@libsql/client';
const db = createClient({
url: process.env.TURSO_DATABASE_URL!,
authToken: process.env.TURSO_AUTH_TOKEN,
});
-
Vercel Postgres
import { sql } from '@vercel/postgres';
const result = await sql`SELECT * FROM users`;
-
PlanetScale (MySQL)
-
Neon (Postgres)
Preview Deployments
Branch Previews
Every git push creates a preview deployment:
https://<project>-<branch>-<team>.vercel.app
- Separate environment variables for preview
Preview Environment Variables
DATABASE_URL (Production): postgres://prod-db...
DATABASE_URL (Preview): postgres://staging-db...
Commenting on PRs
Vercel automatically comments on PRs with:
- Preview URL
- Build status
- Performance metrics
Troubleshooting
Build Failures
npm run build
Environment Variable Issues
vercel env ls
vercel env pull .env.local
Function Timeout
{
"functions": {
"api/long-running.ts": {
"maxDuration": 60
}
}
}
Memory Issues
{
"functions": {
"api/heavy-processing.ts": {
"memory": 1024
}
}
}
Monitoring
Vercel Analytics
import { Analytics } from '@vercel/analytics/react';
export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
<Analytics />
</body>
</html>
);
}
Speed Insights
import { SpeedInsights } from '@vercel/speed-insights/next';
export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
<SpeedInsights />
</body>
</html>
);
}
Function Logs
vercel logs <deployment-url>
vercel logs <deployment-url> --follow
Domains
Custom Domain Setup
- Vercel Dashboard → Domains
- Add domain
- Configure DNS:
- A record:
76.76.21.21
- Or CNAME:
cname.vercel-dns.com
- SSL automatically provisioned
Redirects
{
"redirects": [
{
"source": "/:path((?!api/).*)",
"has": [{ "type": "host", "value": "old-domain.com" }],
"destination": "https://new-domain.com/:path",
"permanent": true
}
]
}
Security
Protected Routes
Use middleware for authentication checks (see Edge Functions above).
Rate Limiting
Implement application-level rate limiting since Vercel doesn't provide built-in rate limiting for serverless functions.
Secrets Management
- Never commit
.env files
- Use Vercel's encrypted environment variables
- Rotate secrets regularly
- Different secrets for preview vs production
References