👋 Next.js Conf 2024: Come build, party, run, and connect with us! See all events

Discussion on interacting with CLI and Sanity Studio v3, outdated CLI version causing issues, and questions on initializing a new project without bundling the studio.

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.
Jan 18, 2023, 5:48 PM
Those should still work! Are you inside the right directory?
Jan 18, 2023, 7:45 PM
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.
Jan 18, 2023, 8:14 PM
It seems like I have access to some of them, but definitely not the full list of commands documented in the docs
Jan 18, 2023, 8:17 PM
What version of the CLI are you on?
Jan 18, 2023, 8:32 PM
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
Jan 18, 2023, 10:25 PM
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
.
Jan 18, 2023, 10:34 PM
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
!
Jan 18, 2023, 10:37 PM
You’re welcome!
Jan 18, 2023, 10:37 PM
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.
Jan 19, 2023, 10:34 AM
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.
Jan 19, 2023, 5:33 PM
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.
Jan 19, 2023, 6:02 PM
I’ll see if I can figure out a cleaner way to do this!
Jan 19, 2023, 6:13 PM
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 😅
Jan 19, 2023, 6:33 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?