Deploy Sanity Studio at /admin route in Next.js on Vercel - stuck on loading

30 replies
Last updated: Nov 30, 2025
Hi,
I have already sent this message but it was in the wrong channel.

I am trying to deploy 
Sanity.io  studio with my Next.js app. What I want to do is to be able to access Sanity studio through an address www.my-domain.com/admin . What is important, i want to deploy it to Vercel. So basically, it should work after build. I do not have issues with a dev mode (I use concurrently and have my next server at port 3000 and Sanity server at port 3333).
I learned a bit from this GitHub repo 
https://github.com/sanity-io/sanity-nextjs-vercel-example  but it is a bit outdated. NPM have introduced workspaces (so I do not use lerna) and deployment of Next.js apps does not require vercel.json. What is in vercel.json is included in my next.config.js with rewrite function (I am mapping contents of built static Sanity studio site to the admin page).
My problem is that whatever I do, when my Sanity studio static site is generated (including not using next.js) by “sanity build” command what appears is only loading Sanity logo with the title “Connecting to 
Sanity.io ”.
Has anyone had the same problem with the built Sanity static pages? Do you know what should I do to make it work?
AI Update

The "Connecting to Sanity.io" screen you're seeing is a classic issue when deploying Sanity Studio to a subpath. This happens because the built Studio is trying to load its assets from the wrong path. Here's how to fix it:

The Core Issue

When you run sanity build, it uses Vite under the hood to bundle the Studio. Without proper configuration, the built files reference assets at the root level (/static/...) instead of your subpath (/admin/static/...).

The Solution: Configure basePath

You need to set the basePath in your sanity.cli.ts (or .js) file:

import {defineCliConfig} from 'sanity/cli'

export default defineCliConfig({
  api: {
    projectId: 'your-project-id',
    dataset: 'production'
  },
  project: {
    basePath: '/admin'  // Critical for subpath deployment!
  }
})

This tells the build process that the Studio will be served from /admin, so all asset references are generated correctly.

Next.js Configuration

Your approach with rewrites in next.config.js is correct:

module.exports = {
  async rewrites() {
    return [
      {
        source: '/admin',
        destination: '/admin/index.html',
      },
      {
        source: '/admin/:path*',
        destination: '/admin/:path*',
      },
    ]
  }
}

Build Process

  1. Run sanity build (this outputs to dist/ by default)
  2. Copy the contents of dist/ to public/admin/ in your Next.js project
  3. Deploy to Vercel

The built files need to be in your public directory so Next.js can serve them as static assets.

Don't Forget CORS

Add your production domain to your Sanity project's CORS settings. Go to your project → API → CORS Origins and add https://www.my-domain.com.

Better Alternative: Embedded Studio

Since you're already using Next.js, consider embedding Sanity Studio directly using the next-sanity package. This is simpler and eliminates the separate build step:

// app/admin/[[...index]]/page.tsx
import {NextStudio} from 'next-sanity/studio'
import config from '../../../sanity.config'

export default function StudioPage() {
  return <NextStudio config={config} />
}

This approach:

  • Runs the Studio as part of your Next.js app (no separate build needed)
  • Works seamlessly with Vercel
  • Automatically handles routing and asset paths
  • Updates when you deploy your Next.js app

The embedded approach is generally recommended for Next.js deployments since it's more integrated and easier to maintain than managing separate static builds.

Show original thread
30 replies

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.

Was this answer helpful?