Sanity CLI dataset and CORS commands not found in Studio v3

13 replies
Last updated: Jan 19, 2023
Hello everyone, I’m wondering how to interact with the CLI and sanity studio v3. It seems that some commands no longer exists (like dataset and CORS)?
Here is the error message I get when I run
sanity help dataset
for example:
Error: Command "dataset" is not available outside of a Sanity project context.

Run the command again within a Sanity project directory, where "@sanity/core" is installed as a dependency.
AI Update

Good news - those commands still exist! The error message is actually telling you exactly what's happening: you need to run these commands from within a Sanity project directory, not just anywhere on your system.

The Context Issue

In Sanity CLI v3, many commands like dataset and cors require you to be inside a Sanity project folder (where @sanity/core is installed as a dependency). This is different from some global CLI operations that can run anywhere.

Here's how to fix this:

  1. Navigate to your Sanity project directory (where your sanity.config.ts or sanity.config.js file lives)
  2. Then run the commands:
cd /path/to/your-sanity-project
sanity dataset list
sanity cors list

Available Dataset & CORS Commands

Once you're in the correct directory, these commands should work:

Dataset commands:

  • sanity dataset list - List all datasets in your project
  • sanity dataset create <name> - Create a new dataset
  • sanity dataset export - Export dataset content
  • sanity dataset import - Import data into a dataset

CORS commands:

  • sanity cors list - List CORS origins
  • sanity cors add <origin> - Add a CORS origin
  • sanity cors delete <id> - Remove a CORS origin

CLI Configuration

Make sure your project has a CLI configuration file (sanity.cli.js or sanity.cli.ts) in the project root with your project ID:

import { defineCliConfig } from "sanity/cli";

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

You can find more details in the official CLI documentation.

If you're trying to manage multiple projects, you'll need to cd into each project's directory before running these context-dependent commands, or use the --project flag where supported to specify which project you're working with.

Show original thread
13 replies
Those should still work! Are you inside the right directory?
I tried with two repos, one with the studio embedded in a route, one with with a standard setup, but I ran into the same issues with both.
Should I run the command in a specific directory? I’m running the command in root, where the sanity.cli.ts file is located.
It seems like I have access to some of them, but definitely not the full list of commands documented in the docs
What version of the CLI are you on?
I’m not sure, but I’m probably using the wrong one @sanity/cli since it’s installed globally, maybe I should try to do
npx sanity@latest [command]
instead
You can try running
npm list -g
to see check the version. It also may be worth it to update with
npm install --global sanity@latest
.
Yeah totally I’m probably on an outdated version. I’ll try tomorrow and will let you know.Thanks a lot for the help
user M
!
You’re welcome!
user M
I was indeed on an outdated CLI version 😅 everything works as expected now. Thanks again!
Quick question, since we can embed the studio inside a route in v3, I’m wondering how I can init a project, without bundling the studio on its own package – basically just creating a new dataset and projectID.
Nice! Glad it was a simple fix! If you’re installing the Sanity inside of an existing app, you’d install it as a dependency like they do here . If you want to add in a new project, I think you can then just run
npm create sanity@latest
to bootstrap a new project and the required config files.
I’ve installed it as a dependency, but when I do
sanity init
– I’d need the CLI to only create a projectID and dataset when it detects a
sanity.cli.ts
file. So far my workflow to create a new project is: run
npm create sanity@latest
to create a new project, delete the folder, use my nextjs template (with embedded studio), copy paste the projectID and dataset from the sanity.io/manage dashboard.
I’ll see if I can figure out a cleaner way to do this!
Maybe initializing a nextjs-app inside a sanity project (and deleting the package.json) is cleaner. But since I’m using my own template I have no clue 😅

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?