How to deploy Next.js app on Vercel
Push your Next.js app to a Git repository, import it into Vercel dashboard via 'New Project', configure build settings and environment variables, then click 'Deploy' for automatic production build on global CDN. Test locally first with <code>npm run build</code> and <code>npm run lint</code> to avoid common failures.
Prerequisites
- A functional Next.js app that builds successfully locally
- Vercel account (sign up at vercel.com)
- Git installed and repository ready (GitHub, GitLab, or Bitbucket)
- Node.js with npm/yarn/pnpm package manager
Step-by-Step Instructions
Prepare Your Next.js App Locally
npm run build to generate production build and verify no errors occur. Also execute npm run lint to catch ESLint issues early, as Vercel enforces all rules during deployment. Ensure your app works in production mode with npm start.Initialize Git Repository
git init
git add .
git commit -m "Initial commit"Run these commands in your project root to stage and commit all files. Create a repository on GitHub, GitLab, or Bitbucket, then push your code: git remote add origin YOUR_REPO_URL followed by git push -u origin main. This prepares your app for Vercel's Git-based deployments.Import Repository in Vercel Dashboard
Review Deployment Settings
npm run build, and Output directory is .next. Set project name (auto-filled from repo) and select deploy branch (usually main). Adjust if using custom setups like pnpm.Configure Environment Variables
DATABASE_URL (server-only) or NEXT_PUBLIC_API_URL (client-safe). Use Vercel dashboard for production secrets; reference them as process.env.VARIABLE in code. System vars like VERCEL_URL are auto-provided.Deploy the App
Access Your Live App
yourproject.vercel.app. Open in browser to verify functionality, including API routes and static pages. App runs on Vercel's global edge network with automatic HTTPS.Set Up Custom Domain (Optional)
Post-Deployment Verification
Common Issues & Troubleshooting
ESLint errors fail deployment despite local success
Run <code>npm run lint</code> locally, fix all violations including warnings. Remove duplicate ESLint configs like <code>.eslintrc.json</code> and <code>.eslintrc.config.mjs</code>. Import missing PropTypes in components.
Build fails due to package manager mismatch (e.g., pnpm)
Set correct <strong>Install command</strong> in Vercel settings (e.g., <code>pnpm install</code>). Match <code>package.json</code> lockfile and run local build with same manager first.
Environment variables not working in production
Add vars in Vercel dashboard under project Settings > Environment Variables. Use <code>NEXT_PUBLIC_</code> prefix for client-side access. Restart deployment after changes.
Serverless functions can't access custom files
Add <code>vercel.json</code> with <code>functions</code> property: <pre><code>{"functions": {"api/*.js": {"includeFiles": "someDir/*.txt"}}}</code></pre>Use glob patterns for paths.
Deployment stuck or timeout during build
Check build logs for memory issues; increase Node version in settings. Build locally first. Exclude large <code>node_modules</code> via <code>.vercelignore</code>.