Issue with running "sanity start" command in a project context

25 replies
Last updated: May 11, 2022
I'm having issues with running "sanity start" I am in the studio directory and I get the following error: Error: Command "start" 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

This error typically means that the CLI can't find the proper Sanity project dependencies in your current directory. Here are the most common causes and solutions:

1. Check your package.json

Make sure you have sanity (or @sanity/core for older versions) listed as a dependency. Your package.json should include something like:

{
  "dependencies": {
    "sanity": "^3.x.x",
    // other dependencies...
  }
}

2. Install dependencies

If you just cloned the project or the dependencies aren't installed, run:

npm install
# or
yarn install
# or
pnpm install

3. Use the correct command

For Sanity v3, the preferred command is actually sanity dev (not sanity start). Try running:

npx sanity dev
# or if you have the CLI installed globally
sanity dev

The sanity start command is legacy from v2. The modern sanity dev command provides better performance with live reloading.

4. Verify you're in the right directory

Make sure you're actually in the Studio directory. Look for:

  • A sanity.config.ts (or .js) file
  • A sanity.cli.ts (or .js) file
  • A package.json with Sanity dependencies

5. Reinstall Sanity if needed

If dependencies are corrupted, try:

npm uninstall sanity
npm install sanity@latest

6. Check for global CLI issues

If you're using a globally installed CLI, it might be outdated. Update it:

npm install -g sanity@latest

After fixing the dependencies, run sanity dev (or npm run dev if that's configured in your package.json scripts) to start your Studio.

Hey there! It may be worth it to try running
sanity install
in the root of the directory once more. It's possible that it's listed as a dependency but not installed.
ok, i'll give it a shot now, thanks for replying
just did that and restarted vs code. Still same issue. So frustrating, I've been trying to search everywhere for a solution and nothing
also, it did work yesterday prior to me running npm run build
not sure if that did anything
It shouldn't. I've just tested it by running
npm run build
then
sanity start
. But to test, you can try deleting
dist
and
node_modules
and then reinstalling.
What does your folder structure look like? Is it possible you're using a monorepo and you're not in the right directory?
I've read about deleting dist and nod_modules, I haven't tried that yet.
I'm sure I'm in the right directory since I was able to use sanity start yesterday and for about a week.
but something must have went of of sync and I don't know what caused it
also when i ran npm run build i encounted an error so not sure if that messed things up
Do you remember what the error was?
I don't remember the error and I restarted the program so it's not in my history.
I just removed node modules via

rm -rf node_modules/
npm install
than reinstalled it.

I than ran sanity install and I still get the issue.

Error: Command "start" 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.

at _.runCommand (C:/nvm/v16.13.2/node_modules/@sanity/cli/bin/sanity-cli.js
:3614:1340) at t.exports (C:/nvm/v16.13.2/node_modules/@sanity/cli/bin/sanity-cli.js
:1986:2422)
I have 2 package.json files, One within the sanity project folder and the other in the Next.js folder
it shows that @sanity/core is in my package.json however it keeps showing that error when I run "sanity start"
It doesn't look like you're inside of a Studio directory. That looks like the structure of a Next project.
buzznextstudio is the sanity folder
I also noticed in the package.json within Studio project, "author": null, displays an error (Incorrect type. expected one of object, string
I meant buzznextsanity is the sanity folder I just pasted above
Your
sanity.json
isn't in the Sanity folder, it's inside of your Next project.
ok, I'll move it in the the sanity folder now
that's what my sanity.json file looks like.
I moved it into the buzznextsanity folder and I get this error
I downgraded to react 16.2 and still have the same error
Error: Command "start" 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.
and as shown in image above, @sanity/core 0.139.2 is the version
well, I sort of took a work around approach, I completely reinstalled from a backup and got it to work. I'm guessing it was something corrusted in the node modules

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?