How do I Deploy Sanity and Next.js (to Vercel) when they Live in a Top Level Folder Side by Side?
When deploying a monorepo with Sanity Studio and Next.js in separate folders to Vercel, you'll need to configure each project individually. Here's how to handle your structure:
Deploying the Structure
For your setup:
my-project/ ├── studio/ └── web/
You'll create two separate Vercel projects, each pointing to the same GitHub repository.
Studio Deployment
Set Root Directory: In Vercel project settings, set the Root Directory to
studioAdd vercel.json in your
studiofolder:{ "version": 2, "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }] }This configures the SPA fallback so all routes work correctly.
Update package.json build script:
{ "scripts": { "build": "sanity build" } }Install Sanity CLI as dependency: Add
@sanity/clito yourpackage.jsondevDependencies (not globally). This was the key fix that solved deployment issues.Output Directory: Set to
dist(Sanity's default build output)Add CORS: After deploying, run:
sanity cors add https://your-studio-url.vercel.app --credentials
Next.js (Web) Deployment
- Set Root Directory: In a separate Vercel project, set Root Directory to
web - Vercel will auto-detect Next.js and configure build settings
- Add your Sanity project ID and dataset as environment variables
Important Notes
- Two Vercel Projects: You need separate Vercel projects for studio and web, both connected to the same repo but with different root directories
- Build Command Location: Make sure dependencies are installed in the correct subfolder, not at the monorepo root
- The Turbo Start Sanity template demonstrates this exact pattern with a working monorepo structure
This approach works well for learning and smaller projects. For production monorepos, consider using tools like Turborepo for better dependency management and build caching.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.