Deploying a Next.js App to Vercel Step by Step
To deploy a Next.js app to Vercel: push your code to GitHub, sign into Vercel with your GitHub account, import the repository, set your environment variables, and click Deploy. Vercel auto-detects Next.js projects, builds them, and gives you a live URL in about 60 seconds. Every future push to your main branch triggers a new deployment automatically.
Before you start: what you need
Make sure you have these three things ready:
- A working Next.js app: It should run locally with
npm run devand build without errors withnpm run build. - A GitHub account: Your code needs to be in a GitHub repository. Vercel also supports GitLab and Bitbucket, but GitHub is the smoothest integration.
- Your environment variables: If your app uses a database (Supabase), API keys (Daraja, Paystack), or any secrets, have them ready. You will enter them in Vercel's dashboard.
Check your build locally first. This catches most deployment failures before they happen:
npm run build
# If this fails locally, it will fail on Vercel too.
# Fix all errors before deploying.Step 1: Push your code to GitHub
If your project is not on GitHub yet:
# Initialize Git (if not already done)
git init
# Create a .gitignore if you do not have one
npx gitignore node
# Stage and commit
git add .
git commit -m "Initial commit"
# Create a repository on github.com, then:
git remote add origin https://github.com/yourusername/your-app.git
git branch -M main
git push -u origin mainMake sure your .gitignore excludes node_modules, .env.local, .next, and any other generated or secret files.
Step 2: Connect Vercel to your repository
Go to vercel.com and sign in with your GitHub account.
- Click "Add New Project" on your Vercel dashboard.
- Vercel shows your GitHub repositories. Find yours and click "Import".
- Vercel auto-detects that it is a Next.js project and pre-fills the build settings:
Framework Preset: Next.jsBuild Command: next build(ornpm run build)Output Directory: .next - You usually do not need to change these defaults.
If Vercel does not auto-detect your framework, check that your package.json has Next.js as a dependency and that it has a build script.
Step 3: Add environment variables
Before clicking Deploy, expand the "Environment Variables" section. Add every variable from your .env.local file:
NEXT_PUBLIC_SUPABASE_URL = https://xyzcompany.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY = eyJhbGciOiJIUzI1NiIs...
DARAJA_CONSUMER_KEY = your_production_key
DARAJA_CONSUMER_SECRET = your_production_secret
DATABASE_URL = postgresql://user:pass@host:5432/dbImportant notes:
- Use your production credentials, not sandbox ones.
- Variables starting with
NEXT_PUBLIC_are exposed to the browser. Only use this prefix for values that are safe to be public. - You can scope variables to specific environments: Production, Preview (pull request deploys), and Development.
You can also add environment variables later from your project settings. If you change them after deployment, you need to redeploy for the changes to take effect:
# Using the Vercel CLI
vercel env add DARAJA_CONSUMER_KEY
# Trigger a redeployment
vercel --prodStep 4: Deploy and set up your custom domain
Click "Deploy". Vercel clones your repository, installs dependencies, runs npm run build, and deploys the output. You will see a build log in real time.
When it finishes, Vercel gives you a URL like your-app.vercel.app. Your site is live.
Adding a custom domain:
- Go to your project settings in Vercel, then Domains.
- Enter your domain name (e.g.,
myapp.co.ke). - Vercel tells you which DNS records to add. Typically:
# For a root domain (myapp.co.ke)
Type: A
Name: @
Value: 76.76.21.21
# For a subdomain (www.myapp.co.ke)
Type: CNAME
Name: www
Value: cname.vercel-dns.comAdd these records at your domain registrar (e.g., KE Hostmaster for .co.ke domains, Namecheap, or Google Domains). DNS propagation can take a few minutes to a few hours.
Vercel automatically provisions an SSL certificate for your domain, so your site will be served over HTTPS.
Troubleshooting common deployment failures
Build fails with TypeScript errors:
Next.js in production mode type-checks your entire project. Errors that do not show during npm run dev (which only checks the page you are viewing) will fail the build. Fix all TypeScript errors locally with npx tsc --noEmit.
Build fails with "Module not found":
A dependency is missing from package.json. Maybe you installed it globally instead of locally. Run npm install missing-package and commit the updated package.json.
Environment variable is undefined:
Check three things: (1) the variable is set in Vercel's environment settings, (2) it is scoped to the correct environment (Production vs Preview), and (3) you redeployed after adding it.
API routes return 500 errors:
Check the Vercel function logs in your project dashboard under Deployments, then click on the deployment and view Functions. The error message will tell you what went wrong.
Page loads but looks broken (no styles):
Check your Tailwind configuration. Make sure content in tailwind.config.ts includes all files that use Tailwind classes. Also check that you are not importing CSS files from the wrong path.
// tailwind.config.ts
export default {
content: [
'./app/**/*.{js,ts,jsx,tsx}',
'./src/**/*.{js,ts,jsx,tsx}',
'./components/**/*.{js,ts,jsx,tsx}',
],
// ...
};Frequently Asked Questions
- Is Vercel free?
- Vercel has a generous free tier (Hobby plan) that includes unlimited deployments, 100 GB bandwidth per month, and serverless function execution. It is more than enough for personal projects, portfolios, and small apps. You only need a paid plan when you have a team or high traffic.
- Does every git push trigger a deployment?
- Every push to your main branch triggers a production deployment. Pushes to other branches and pull requests trigger preview deployments with unique URLs, which is great for testing changes before merging. You can disable this behavior in your project settings.
- Can I deploy to Vercel without GitHub?
- Yes. You can use the Vercel CLI to deploy directly from your terminal with the command "vercel". This uploads your code without needing a Git repository. However, connecting to GitHub gives you automatic deployments, preview URLs for pull requests, and rollback capabilities.
- What about deploying to other platforms?
- Next.js also deploys to Netlify, Railway, Render, AWS Amplify, and any platform that supports Node.js. Vercel is the smoothest option because Vercel created Next.js, so the integration is seamless. But you are not locked in.
Ready to build real-world apps?
Join the McTaba Labs full-stack marathon. Ship 8 production apps with M-Pesa, USSD, and WhatsApp integrations, and get career support until placement.
See Programs