Error deploying new version of graphql API due to missing Sanity studio file

2 replies
Last updated: May 30, 2023
Hi! I'm trying to deploy a new version of the graphql API, but I get this error
Error: Expected Sanity studio of version 3 or above
These are the versions I'm using:

@sanity/cli           3.11.3 (up to date)
@sanity/dashboard      3.1.4 (up to date)
@sanity/icons          2.3.1 (up to date)
@sanity/vision        3.11.3 (up to date)
sanity                3.11.3 (up to date)
Does anyone know what this problem means, or how to solve it?
AI Update

I understand how frustrating this error is! The "Expected Sanity studio of version 3 or above" message when deploying GraphQL can be confusing, especially since your packages clearly show Studio v3 installed.

Based on the GraphQL deployment documentation, here are the most likely causes and solutions:

1. Check your sanity.cli.js configuration

The sanity graphql deploy command requires a properly configured sanity.cli.js (or sanity.cli.ts) file in your project root with API credentials:

import { defineCliConfig } from 'sanity/cli'

export default defineCliConfig({
  api: {
    projectId: 'your-project-id',
    dataset: 'production'
  }
})

If this file is missing or doesn't have the api.projectId configured, the CLI can't properly detect your project setup, which may trigger version detection issues.

2. Verify you're in the correct directory

Make sure you're running the command from your Sanity project root directory (where your schema files and configuration are located), not from a parent or subdirectory.

3. Try specifying the dataset explicitly

Run the deploy command with explicit parameters:

sanity graphql deploy --dataset production

4. Check if you have workspace configurations

If you're using multiple workspaces, you may need to configure GraphQL deployment in your sanity.cli.js to specify which workspace to deploy:

export default defineCliConfig({
  api: {
    projectId: 'your-project-id',
    dataset: 'production'
  },
  graphql: [
    {
      id: "production",
      workspace: "production",
    }
  ]
})

5. Try a fresh install

Sometimes dependency issues can cause detection problems:

rm -rf node_modules package-lock.json
npm install
sanity graphql deploy

The error message suggests the CLI is having trouble detecting your Studio v3 setup, which is typically a configuration file issue rather than a package version problem. Once your sanity.cli.js is properly configured with the required API settings, the GraphQL deployment should work correctly.

What does your cli config look like?
Looks like I was missing a
sanity.cli.js
file, I've added it and it's now working. It's not clear from the docs that it's required though (unless I missed something).Thanks for the help!

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?