Sanity "Configuration must contain projectId" Error
This error means your Sanity Studio configuration is missing the projectId value, which is required to connect to your Sanity project. Here's how to fix it:
Quick Fix
Find your Project ID: Log into sanity.io/manage and locate your project ID in the dashboard
Add it to your configuration: Open your Sanity config file (usually
sanity.config.tsorsanity.config.js) and make sure it includes yourprojectId:
import {defineConfig} from 'sanity'
export default defineConfig({
projectId: 'your-project-id-here', // ← Add this
dataset: 'production',
// ... rest of your config
})If You're Using Environment Variables
For Next.js or other frameworks, you might be using environment variables. Make sure:
- Your
.env.localfile has the correct variables:
NEXT_PUBLIC_SANITY_PROJECT_ID=your-project-id-here
NEXT_PUBLIC_SANITY_DATASET=productionNote: In Next.js, the NEXT_PUBLIC_ prefix is required for client-side access.
- Your config file references them correctly:
import {defineConfig} from 'sanity'
export default defineConfig({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
// ... rest of your config
})- Restart your dev server after adding environment variables - they're only loaded on startup
Common Gotchas
- Using a template? Make sure you've replaced the placeholder project ID with your actual one. Search your entire codebase for
projectIdto find all instances. - Project ID is public: Don't worry about exposing it - project IDs aren't sensitive information and will be visible in your production code anyway.
Once you add the correct projectId to your configuration, the error should disappear and your Studio will load properly!
Show original thread9 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.