3

I am trying to install the Sanity studio and I followed these steps:

npm install --global @sanity/cli

sanity install

sanity init

After the init step, I try to run the next step:

sanity start

but it says:

Run the command again within a Sanity project directory, where "@sanity/core"
is installed as a dependency.
    at D.runCommand (F:/All Node and related projects/node_modules/@sanity/cli/b
in/sanity-cli.js:3254:1345)
    at t.exports (F:/All Node and related projects/node_modules/@sanity/cli/bin/sanity-cli.js:1794:2419)

But when I try to cd into my sanity project directory, it is not even able to recognize sanity, it says:

'sanity' is not recognized as an internal or external command,
operable program or batch file.

Is my dependencies directory structure incorrect? What conditions should be met before you can call sanity start?

THANKS!

8 Answers 8

7

I ran into a similar problem wen trying to initialize Sanity. I tried all the above which didn't work form me. As advised above I would run

npm install -g @sanity/cli

then:

sanity init

And I would get the following error:

sanity : The term 'sanity' is not recognized as the name of a cmdlet

The solution I found to this was running the following instead:

npx @sanity/cli init

npx @sanity/cli start

This worked for me like a charm!

0

The reason why sanity start not working is your command prompt location not same as you installed all sanity packages.

Go back to commend prompt go to the location where sanity is installed and give the commend sanity start it will work .

2
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Feb 13, 2022 at 9:56
  • If you install it globally (with the -g flag), this is not the issue.
    – paddotk
    Oct 13, 2022 at 10:59
0

usually, sanity is set in "studio" directory. In root we install

npm i @sanity/client

and then create "studio" directory in root. cd into "studio"

 cd studio

and inside "studio" directory

 sanity init

This will initialize sanity project inside "studio" directory

enter image description here

If you open the package.json inside "studio", you should have those scripts:

"scripts": {
    "start": "sanity start",
    "build": "sanity build"
  },

Since you are running sanity start in root level, in root package.json file, "start": "sanity start" does not exist that is why you are getting error

To start the sanity server, everytime you should cd studio and then sanity start. Technically you will have two terminals: one for main project development server and second one is for the sanity server

0

When you run sanity init , it creates a folder for the project (you can choose e-commerce, blog, or no template). cd into that folder that got created and then you can run sanity start

If you can't find where that folder is, you can just create a new one. Sanity is already installed, so you can just go ahead with sanity init

If you're using it with a front end framework, go into the root directory of your project, run the command there, then cd into the created folder then start sanity.

0

just cd into sanity folder by writing cd sanity and then sanity start

0

Same issue happened with me then I rechecked whether I'm in the right directory and noticed that I was in the backend directory, then I cd.. and got into the right frontend directory and ran 'npm run dev' and guess what it compiled successfully. So make sure that you are in the right directory.

0

cd into the sanity folder and yarn dev works for me with the scripts below (you can also use npm run dev)

"scripts": {
    "start": "sanity start",
    "build": "sanity build",
    "dev": "sanity dev"
  },

If I do sanity dev it gives me that error

-1

I encountered this problem sometime, all I did was cd into my sanity folder then run ~ npm install ~ and that solved it for me

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.