Vercel makes deploying React apps ridiculously easy. No servers to manage, no complex configuration, and automatic deployments every time you push to Git. In this guide, I'll show you how to deploy your React app to Vercel in under 5 minutes.
This works for Create React App, Vite, Next.js, and any other React framework.
Prerequisites
- A React app (created with CRA, Vite, Next.js, etc.)
- A GitHub, GitLab, or Bitbucket account
- Your code pushed to a Git repository
💡 Don't have a React app yet?
Create one quickly with:
# Using Vite (recommended)
npm create vite@latest my-app -- --template react
cd my-app
npm install
# Or using Create React App
npx create-react-app my-app
cd my-app
Step-by-Step Deployment
1 Push Your Code to GitHub
If you haven't already, push your React app to GitHub:
# Initialize git (if not already done)
git init
git add .
git commit -m "Initial commit"
# Create a new repository on GitHub, then:
git remote add origin https://github.com/yourusername/your-repo.git
git branch -M main
git push -u origin main
2 Sign Up for Vercel
Go to vercel.com and sign up with your GitHub account. It's free for personal projects and open source.
Vercel's free tier includes:
- Unlimited deployments
- 100 GB bandwidth per month
- Automatic HTTPS
- Preview deployments for pull requests
3 Import Your Repository
Once logged in to Vercel:
- Click "Add New..." → "Project"
- You'll see your GitHub repositories listed
- Find your React app repository and click "Import"
4 Configure Build Settings
Vercel automatically detects most React frameworks. Here are the settings for common setups:
For Create React App:
- Framework Preset: Create React App
- Build Command:
npm run build(auto-detected) - Output Directory:
build(auto-detected)
For Vite:
- Framework Preset: Vite
- Build Command:
npm run build(auto-detected) - Output Directory:
dist(auto-detected)
For Next.js:
- Framework Preset: Next.js
- Build Command:
npm run build(auto-detected) - Output Directory:
.next(auto-detected)
💡 Pro Tip
If Vercel doesn't auto-detect your framework, select it manually from the "Framework Preset" dropdown. This enables framework-specific optimizations.
5 Add Environment Variables (If Needed)
If your app uses environment variables (API keys, database URLs, etc.), add them in the "Environment Variables" section:
- Click "Add" for each variable
- Enter the name (e.g.,
REACT_APP_API_KEY) - Enter the value
- Select environments (Production, Preview, Development)
⚠️ Important
For Create React App, prefix variables with REACT_APP_. For Vite, use VITE_. Variables without these prefixes won't be available in your app.
6 Deploy!
Click "Deploy" and wait 30-60 seconds. Vercel will:
- Clone your repository
- Install dependencies
- Build your app
- Deploy to their global CDN
Once complete, you'll get a URL like https://your-app.vercel.app. Your app is now live!
Setting Up a Custom Domain
Want to use your own domain instead of .vercel.app?
- Go to your project settings in Vercel
- Click "Domains"
- Enter your domain (e.g.,
myapp.com) - Vercel will show you DNS records to add
- Add these records to your domain registrar
- Wait for DNS propagation (usually 5-30 minutes)
Common DNS Configurations
For apex domain (example.com):
Type: A
Name: @
Value: 76.76.21.21
For www subdomain (www.example.com):
Type: CNAME
Name: www
Value: cname.vercel-dns.com
💡 Automatic HTTPS
Vercel automatically provisions and renews SSL certificates for your custom domain. No need to use Let's Encrypt or Certbot!
Automatic Deployments
One of Vercel's best features: every time you push to your Git repository, Vercel automatically deploys your changes.
# Make changes to your code
git add .
git commit -m "Update homepage"
git push
# Vercel automatically deploys! 🚀
Preview Deployments
When you create a pull request, Vercel creates a preview deployment with a unique URL. This lets you test changes before merging to production.
Preview URLs look like: https://your-app-git-feature-branch.vercel.app
Configuring Build and Output Directories
If Vercel doesn't auto-detect your build settings, you can configure them manually:
In the Vercel Dashboard:
- Go to Project Settings → General
- Update "Build Command" and "Output Directory"
- Click "Save"
- Redeploy your project
Using vercel.json:
Create a vercel.json file in your project root:
{
"buildCommand": "npm run build",
"outputDirectory": "dist",
"framework": "vite",
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}
💡 SPA Routing Fix
If you're using React Router and getting 404 errors on page refresh, add the "rewrites" configuration above. This tells Vercel to serve index.html for all routes.
Environment Variables
Managing environment variables in Vercel:
Adding Variables:
- Go to Project Settings → Environment Variables
- Add variables for Production, Preview, and Development
- Use the same variable names as in your local
.envfile
Accessing Variables in Code:
Create React App:
// .env file
REACT_APP_API_URL=https://api.example.com
// In your code
const apiUrl = process.env.REACT_APP_API_URL;
Vite:
// .env file
VITE_API_URL=https://api.example.com
// In your code
const apiUrl = import.meta.env.VITE_API_URL;
⚠️ Security Note
Never commit sensitive API keys to your repository. Always use environment variables, and only expose keys that are safe to be public (like frontend API keys).
Troubleshooting Common Issues
Build Fails with "Module not found"
This usually means a dependency is missing. Check:
- All dependencies are in
package.json - You're not importing from
node_modulesdirectly - Try deleting
node_modulesandpackage-lock.json, then reinstall
rm -rf node_modules package-lock.json
npm install
git add .
git commit -m "Reinstall dependencies"
git push
404 Errors on Page Refresh (SPA)
If you're using React Router and get 404 errors when refreshing or directly accessing routes:
Create vercel.json in your project root:
{
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}
Environment Variables Not Working
Check:
- Variables are prefixed correctly (
REACT_APP_orVITE_) - Variables are added to the correct environment (Production/Preview/Development)
- You've redeployed after adding variables
- You're accessing them correctly in code
Build Takes Too Long
If your build is slow:
- Enable Vercel's build cache (enabled by default)
- Optimize your build process (e.g., use Vite instead of CRA)
- Consider upgrading to Vercel Pro for faster builds
Advanced Configuration
Custom Build Scripts
If you need custom build logic, update your package.json:
{
"scripts": {
"build": "npm run lint && npm run test && vite build",
"preview": "vite preview"
}
}
Monorepo Support
If your React app is in a subdirectory of a monorepo:
- In Vercel, set "Root Directory" to your app's folder
- Example: If your app is in
apps/web, set Root Directory toapps/web
Serverless Functions
Vercel supports serverless functions for backend logic:
Create api/hello.js:
export default function handler(req, res) {
res.status(200).json({ message: 'Hello from Vercel!' });
}
Access it at https://your-app.vercel.app/api/hello
Monitoring and Analytics
Vercel provides built-in analytics:
- Speed Insights: Real user performance metrics
- Analytics: Page views, visitors, and more
- Logs: Real-time function and build logs
Enable analytics in Project Settings → Analytics.
Rolling Back Deployments
If a deployment breaks your app:
- Go to your project's "Deployments" page
- Find the last working deployment
- Click the three dots → "Promote to Production"
- Your app is instantly rolled back
Summary
You've successfully deployed your React app to Vercel! Here's what you accomplished:
- ✅ Deployed your app with zero configuration
- ✅ Set up automatic deployments from Git
- ✅ Configured environment variables
- ✅ (Optional) Added a custom domain
- ✅ (Optional) Fixed SPA routing issues
Your app is now live on Vercel's global CDN, with automatic HTTPS and instant rollbacks. Every time you push to Git, your changes will be live in under a minute.
Next Steps
- Set up a custom domain for your app
- Enable Vercel Analytics to track performance
- Add serverless functions for backend logic
- Configure preview deployments for pull requests
- Explore Vercel's Edge Functions for low-latency responses