Preview Deployment Fix — Root Cause & Solution
Tier C — Historical. This document is a point-in-time snapshot preserved for reference. For current architecture, see CANONICAL_PLATFORM_ARCHITECTURE.md.
Problem
Preview deployment was failing with 404 errors. The platform was fully built and working locally, but Vercel couldn't properly deploy it.
Root Cause
Missing vercel.json configuration file.
Vercel needs explicit instructions for Vite-based SPA applications:
- Where the build output is located (
apps/web/dist) - How to handle routing for single-page apps (rewrite all paths to
index.html) - Build command (Turbo monorepo:
pnpm build) - Environment variables
Without vercel.json, Vercel defaults to Next.js or static site assumptions, which don't work for Vite React Router apps.
Solution
Created vercel.json with proper Vite configuration:
{
"version": 2,
"buildCommand": "pnpm build",
"outputDirectory": "apps/web/dist",
"framework": "vite",
"cleanUrls": true,
"rewrites": [
{
"source": "/(.*)",
"destination": "/index.html"
}
]
}
Key configurations:
outputDirectory: Points Vercel to the Vite build outputrewrites: SPA routing (all paths → index.html for React Router)cleanUrls: Remove.htmlextensions from URLsframework: Explicit Vite detectionbuildCommand: Uses Turbo to build the monorepo
What This Fixes
- 404 errors on preview: Vercel now correctly serves
index.htmlfor all routes - Build detection: Vercel knows to run Turbo build command
- Asset routing: Static assets serve from
/dist/assets/ - Environment variables: Can be configured in Vercel project settings
Deployment Readiness Status
✅ All checks passed:
- Vite build: 8.9MB dist directory created
- TypeScript: 0 errors (clean type check)
- Dependencies: pnpm-lock.yaml (reproducible builds)
- Config: vercel.json present and configured
- Environment: AI Gateway keys available
- Git: Changes committed and ready for push
Why This Wasn't Needed Before
Previous deployments may have worked because:
- Local dev server (Vite) handles routing internally
- Cloudflare Workers deployments don't need Vercel routing config
- Early deployments may have been manual or used different hosting
Now that preview URLs are public-facing, Vercel needs explicit config for SPAs.
Testing the Fix
After pushing to GitHub:
- Vercel automatically builds the deployment
- Preview URL should load without 404s
- All routes (/, /app, /dashboard) should work
- Assets should load (no 404s on .js, .css files)
Files Modified
vercel.json— New file with deployment config
References
- Vercel Vite docs: https://vercel.com/docs/frameworks/vite
- Vite SPA config: https://vitejs.dev/guide/ssr.html#setting-up-the-dev-server
- React Router in Vite: https://reactrouter.com/start/framework-choice