Error in Sanity CLI configuration and deployment, resolved with the addition of a missing file.
This error means your sanity.cli.js file is missing the required projectId configuration that the CLI needs to communicate with Sanity's API. Here's how to fix it:
Quick Fix
Create or update your sanity.cli.js file in the root of your project with this minimal configuration:
import { defineCliConfig } from 'sanity/cli'
export default defineCliConfig({
api: {
projectId: 'your-project-id',
dataset: 'production'
}
})Replace 'your-project-id' with your actual Sanity project ID (you can find this in your Sanity manage dashboard).
Better Approach with Environment Variables
It's better practice to use environment variables:
import { defineCliConfig } from 'sanity/cli'
export default defineCliConfig({
api: {
projectId: process.env.SANITY_STUDIO_PROJECT_ID,
dataset: process.env.SANITY_STUDIO_DATASET
}
})Then add these to your .env file:
SANITY_STUDIO_PROJECT_ID=your-project-id SANITY_STUDIO_DATASET=production
TypeScript Version
If you're using TypeScript, create sanity.cli.ts instead:
import { defineCliConfig } from 'sanity/cli'
export default defineCliConfig({
api: {
projectId: process.env.SANITY_STUDIO_PROJECT_ID!,
dataset: process.env.SANITY_STUDIO_DATASET!,
}
})Important Note
The sanity.cli.js configuration file is specifically for CLI operations. If this file is missing or incomplete, the CLI will try to fall back to your sanity.config.ts file, but it's best practice to have both properly configured. The CLI config is what allows commands like sanity deploy, sanity dataset, and other CLI operations to know which project they're working with.
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.