
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI can help you troubleshoot this "Project ID is not set" error! This is a common issue when setting up a Sanity-Next project, and it usually comes down to environment variable configuration and understanding the difference between Sanity Studio and Next.js environment variables.
First, it's important to know that Sanity Studio and Next.js use different environment variable conventions:
SANITY_STUDIO_ prefix for its environment variablesNEXT_PUBLIC_ prefix for client-side environment variablesThese are separate systems with different requirements.
If you're getting the "Project ID is not set" error in your Next.js app (not in Sanity Studio), your .env.local file should be in the root of your Next.js application folder.
Create or edit .env.local in your Next.js root:
NEXT_PUBLIC_SANITY_PROJECT_ID="your-project-id-here"
NEXT_PUBLIC_SANITY_DATASET="production"The NEXT_PUBLIC_ prefix is a Next.js requirement for exposing variables to client-side code. This has nothing to do with Sanity - it's how Next.js handles environment variables in the browser.
Then use these in your Sanity client configuration:
import { createClient } from '@sanity/client';
export const client = createClient({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
apiVersion: '2024-01-01',
useCdn: true,
});If you need environment variables in your Sanity Studio itself, you'd use a different approach with .env.development or .env.production files in your Studio folder:
SANITY_STUDIO_API_PROJECT_ID=your-project-id
SANITY_STUDIO_API_DATASET=productionNote the SANITY_STUDIO_ prefix instead. These are only for configuring the Studio application itself, not for your Next.js frontend.
You can find your Project ID in:
sanity.config.js or sanity.config.ts file (in the Studio folder)sanity projects list in your terminalThe Project ID is not sensitive information - it will be visible in your frontend code and image URLs, so it's safe to commit to version control.
Many Sanity-Next projects have separate folders:
my-project/ ├── studio/ (Sanity Studio - uses SANITY_STUDIO_ variables) └── app/ (Next.js app - needs NEXT_PUBLIC_ variables in .env.local)
Make sure your .env.local is at the root of wherever your Next.js package.json is located.
.env.local, you must restart your Next.js development serverprocess.env.NEXT_PUBLIC_SANITY_PROJECT_ID.env.local file and where you reference the variablesThe key takeaway: NEXT_PUBLIC_ is for Next.js client-side code, while SANITY_STUDIO_ is specifically for Sanity Studio configuration. For a Next.js app consuming Sanity data, you'll use NEXT_PUBLIC_ prefixed variables.
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