Discussion on deleting and reinstalling Sanity CLI package and resolving related issues.

7 replies
Last updated: Jul 26, 2022
How do I delete Sanity? I will reinstall it again right away, as I think it'll be much easier with the issues I am having. However, it's saying either, "A valid session is required at this endpoint" or "Cannot delete user while being the last administrator of a project".  The error I am getting from a project I was getting was" 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 (/usr/local/lib/node_modules/@sanity/cli/bin/sanity-cli.js:3608:1340)
    at t.exports (/usr/local/lib/node_modules/@sanity/cli/bin/sanity-cli.js:1980:2422)
AI Update

Based on your error message, it looks like you're dealing with a few separate issues that don't actually require deleting your Sanity account or completely uninstalling everything. Let me break down what's happening and how to fix it:

Understanding the Main Error

The error Command "start" is not available outside of a Sanity project context means you're trying to run sanity start from a directory that isn't a Sanity project. The Sanity CLI commands (like sanity start or sanity dev) need to be run from inside a Sanity project folder where @sanity/core is installed as a dependency.

You Don't Need to Delete Your Account

The errors about "Cannot delete user while being the last administrator of a project" and "A valid session is required" are appearing because you're trying to delete your account, but:

  1. You can't delete your account if you're the only admin on a project
  2. Deleting your account won't fix the CLI issue anyway

Good news: You don't need to delete your account or uninstall Sanity globally to fix this!

The Solution

Based on the discussion you found, here's what actually works:

1. Make sure you're in the right directory

The sanity start command only works when you're inside your Sanity project folder. Use cd to navigate to your project directory first:

cd path/to/your/sanity-project

2. If you want a fresh start with a new project

Instead of deleting your account, just create a new Sanity project using the modern approach:

npm create sanity@latest

This will guide you through creating a new project with an interactive setup. When you run this command, it will:

  • Let you log in (or create an account)
  • Ask you to create or select a project
  • Set up a dataset
  • Choose a template
  • Install dependencies

Then you can start your studio with:

npm run dev

Or if you're using the older CLI pattern:

sanity dev

3. If you have old project folders cluttering your computer

You can safely delete old project folders from your file system without affecting your Sanity account or other projects. These are just local files. Search for folders containing sanity.config files and delete the ones you don't need.

4. About the CLI versions

If you have the global CLI installed and want to ensure you're using the latest version:

npm install -g @sanity/cli@latest

Or you can use npx to always run the latest version without a global install:

npx sanity@latest init

Current Best Practice (Studio v3)

The modern way to create a Sanity project is:

npm create sanity@latest

This is cleaner than the older sanity init approach and will set everything up correctly from the start.

Your existing projects in your Sanity account will remain untouched - you're just creating new local project folders on your computer that connect to them.

I guess it would involve uninstall the Sanity CLI package you installed globally. Unless you meant closing your Sanity account?
It took me a bit, being new to this as well, but once you install sanity/cli, you will then be able to create a sanity project. You'll do that running sanity init. That process will create the end path where your sanity project will live. As a starter, I suggest you make your final path /studio. That directory will be a sanity project. Most of the commands you'll need to run will only work in that directory, so you will first have to cd to it (cd studio). Immediately run sanity --help to see the commands. For example, you can't run sanity uninstall unless you are in that folder first.
I may not be totally right on this but I had unintentionally installed version 3 of the sanity cli. It may be great, but as a beginner I was trying to get a handle on v2. They are significantly different. So, I first uninstalled my global installation of v3. I then installed v2 globally.

I then found I could install v3 locally in the folder I was working my main web project on. I found that both were present, so I had to be careful to give my v2 commands as simple sanity <something>, as opposed to npx sanity <something> for v3.

After installing the cli, you most likely would be running sanity start, but make sure you first cd into the sanity project folder. If you didn't change the final path to /studio, you should pay attention to the name it is given during the init process.

Best of luck.
I don't see an option to close my account. I searched for it on its site. And there are just too many sanity folders on my computer to determine which one to delete and of course, it's not uninstalling if I am just trashing sanity. Of course, if I don't have to delete my account or uninstall, much better. But that may require me more time to figure out. I have other sanity projects btw. I am ok with deleting them also just to be able to start fresh.
Ray, I figured you know how to go through all these folders to determine where to even start uninstalling sanity?
I figured it out. I searched for all my previous sanity projects and deleted all of them. It's ok. It turned out they were all unfinished projects. This was the easiest for me to figure out. The only problem I encountered was the duplication. I put it in my folder with subfolder of d-portfolio. When I was prompted to give a Project Name, I wrote down d-portfolio. So Development/d-portfolio/d-portfolio for me to able to use sanity start. But at least it worked finally. Thanks
Wonderful you were able to solve your problem
user V
!

user N
you can also get a specific version installed without uninstalling the excisting one:
npm install <package>@<version>
or
yarn add <package>@<version>
Example:

yarn add @sanityt/cli@*2.30.2*
Thanks. The problem I was having was that I unintentionally upgraded my 2.30.2 global install to the version 3. Once that is done, could I still have done a local installation of 2.30.2?

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?