Prerequisites
- A Vercel account (sign up here)
- Node.js and pnpm (or npm/yarn) installed
- A TanStack Start application
Configuration
Install Nitro
TanStack Start uses Nitro as the deployment adapter for Vercel. Install the nightly version:package.json:
Update Vite Config
Add the Nitro plugin to yourvite.config.ts:
Build Scripts
Ensure yourpackage.json has the correct build scripts:
Deployment Methods
Deploy with Vercel CLI
Install the Vercel CLI:- Linking to an existing project or creating a new one
- Configuring project settings
- Deploying your application
Deploy with Git Integration
- Push your code to GitHub, GitLab, or Bitbucket
- Import your repository in the Vercel Dashboard
- Vercel automatically detects your framework and configuration
- Click Deploy
- Automatic deployments on git push
- Preview deployments for pull requests
- Easy rollbacks to previous deployments
One-Click Deploy
Add a deploy button to your repository README:Environment Variables
In Vercel Dashboard
- Go to Project Settings > Environment Variables
- Add your variables
- Select environments (Production, Preview, Development)
- Save changes
Accessing Variables
Environment variables are available throughprocess.env:
Local Development
Create a.env.local file for local development:
Add
.env*.local to your .gitignore to prevent committing secrets.Build Configuration
vercel.json
Create avercel.json file for advanced configuration:
Build Settings in Dashboard
Alternatively, configure in the Vercel Dashboard:- Go to Project Settings > General
- Set Framework Preset to “Other”
- Set Build Command to
pnpm build - Set Output Directory to
.output - Set Install Command to
pnpm install
Advanced Configuration
Custom Headers
Add headers invercel.json:
Redirects and Rewrites
Regions Configuration
Configure serverless function regions:iad1- Washington, D.C., USAsfo1- San Francisco, USAgru1- São Paulo, Brazillhr1- London, UKhnd1- Tokyo, Japan- And more…
Function Configuration
Configure serverless functions invercel.json:
Preview Deployments
Vercel automatically creates preview deployments:- Push to any branch or open a pull request
- Vercel builds and deploys a preview
- Preview URL is posted as a comment on PRs
- Each commit gets a unique preview URL
Configure Preview Deployments
Control preview behavior invercel.json:
Custom Domains
Add a Domain
- Go to Project Settings > Domains
- Add your custom domain
- Configure DNS records as instructed
- Vercel automatically provisions SSL certificates
Domain Configuration
Redirect www to apex domain:Edge Configuration
Edge Functions
Deploy functions to Vercel’s Edge Network for lowest latency:Edge Middleware
Create middleware for authentication, redirects, etc.:Performance Optimization
Caching
Configure caching headers:Image Optimization
Vercel automatically optimizes images. Use the Image component:Monitoring and Analytics
Vercel Analytics
Enable analytics in your dashboard:- Go to Analytics tab
- Enable Web Analytics
- View real-time and historical data
Speed Insights
Monitor Core Web Vitals:- Enable Speed Insights in dashboard
- Track TTFB, FCP, LCP, CLS, and more
- Get actionable recommendations
Resources
Troubleshooting
Build Errors
If your build fails:- Check build logs in Vercel dashboard
- Verify Nitro is installed correctly
- Ensure
vite buildworks locally - Check Node.js version compatibility (set in Project Settings > General)
Runtime Errors
For serverless function errors:- Check Functions logs in Vercel dashboard
- Verify environment variables are set
- Test locally with
vercel dev - Check function timeout limits (default: 10s, max: 300s on Pro)
Deployment Issues
If deployments are failing:- Verify Git integration is configured correctly
- Check branch settings in Project Settings > Git
- Ensure build command is correct
- Try deploying with CLI:
vercel --prod
Performance Issues
For slow response times:- Use Edge Functions for dynamic content
- Configure appropriate caching headers
- Optimize serverless function cold starts
- Consider upgrading to Pro for better performance
- Check function region configuration