Sanity "Configuration must contain projectId" Error

9 replies
Last updated: Nov 29, 2025
AI Update

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

  1. Find your Project ID: Log into sanity.io/manage and locate your project ID in the dashboard

  2. Add it to your configuration: Open your Sanity config file (usually sanity.config.ts or sanity.config.js) and make sure it includes your projectId:

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:

  1. Your .env.local file has the correct variables:
NEXT_PUBLIC_SANITY_PROJECT_ID=your-project-id-here
NEXT_PUBLIC_SANITY_DATASET=production

Note: In Next.js, the NEXT_PUBLIC_ prefix is required for client-side access.

  1. 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
})
  1. 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 projectId to 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 thread
9 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?