
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI understand you've installed Sanity into your Next.js project but are encountering errors when trying to run the studio. Since you haven't provided the specific error messages, I'll cover the most common setup issues and their solutions based on the official documentation.
The most frequent issue is incorrect route setup. For Next.js App Router, your studio route should be structured like this:
File location: app/studio/[[...tool]]/page.tsx
import { NextStudio } from 'next-sanity/studio'
import config from '../../../sanity.config'
// This exports metadata for proper mobile rendering and SEO
export { metadata } from 'next-sanity/studio/metadata'
export default function StudioPage() {
return <NextStudio config={config} />
}Key points:
[[...tool]] is crucial for Studio navigation to workmetadata export handles necessary meta tagssanity.config.ts must have basePath: '/studio' matching your routeYour sanity.config.ts should be at the root of your project (not inside /app or /src):
'use client'
import { defineConfig } from 'sanity'
import { structureTool } from 'sanity/structure'
export default defineConfig({
basePath: '/studio', // Must match your route path
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!,
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET!,
plugins: [structureTool()],
schema: {
types: [] // Add your schema types here
}
})Ensure your .env.local file has these variables with the NEXT_PUBLIC_ prefix (required for browser access):
NEXT_PUBLIC_SANITY_PROJECT_ID=your-project-id NEXT_PUBLIC_SANITY_DATASET=production
You must add your domain to Sanity's CORS origins settings with authenticated requests enabled. This is easy to forget but critical. For local development, add:
http://localhost:3000 (or whatever port you're using)Verify you have the required dependencies installed:
npm install next-sanity sanity styled-componentsFor npm v7+, peer dependencies should install automatically. If you're using an older version or encountering module errors, you may need to install them manually.
If you're using the Pages Router instead, the setup is different:
File location: pages/studio/[[...index]].tsx
import Head from 'next/head'
import { NextStudio } from 'next-sanity/studio'
import { metadata } from 'next-sanity/studio/metadata'
import config from '../../sanity.config'
export default function StudioPage() {
return (
<>
<Head>
{Object.entries(metadata).map(([key, value]) => (
<meta key={key} name={key} content={value} />
))}
</Head>
<NextStudio config={config} />
</>
)
}http://localhost:3000/studiorm -rf .next and rebuildTo get more targeted assistance, please share:
package.json)The official embedding documentation and next-sanity GitHub repository have additional troubleshooting information and examples you can reference.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store