Sanity installation error: something missing after installing in project folder

20 replies
Last updated: Feb 23, 2021
I just tried installing sanity inside of my project folder (I failed to do that before) and now I'm getting a different error about something missing.
AI Update

It sounds like you're running into a common issue when installing Sanity in an existing project folder. Since you mentioned it's a "different error about something missing," there are a few likely scenarios:

Most Common Issue: Missing Dependencies

After running sanity init in your project folder, you need to actually install the dependencies. The init command creates the configuration files but doesn't always automatically install packages. Try running:

npm install
# or if you use yarn
yarn install
# or if you use pnpm
pnpm install

If You're Working with React or Next.js

If you initialized Sanity inside an existing React/Next.js project, you might be missing the core Sanity packages. Make sure these are installed:

npm install sanity @sanity/vision

Check for Version Conflicts

Sometimes you'll get errors about missing peer dependencies or version mismatches, especially with @sanity/ui. The missing context error documentation explains that multiple versions of the sanity package can cause issues. Try:

npm list sanity

If you see multiple versions, you may need to clean your node_modules and reinstall:

rm -rf node_modules package-lock.json
npm install

Starting Fresh in the Right Order

For future reference, the correct sequence when getting started with the Sanity CLI is:

  1. Install the Sanity CLI globally (if you haven't): npm install -g sanity@latest
  2. Run sanity init in your project folder
  3. Run npm install to install all dependencies
  4. Start the development server: npm run dev or sanity dev

If you can share the specific error message you're seeing, I can give you more targeted help! Common error messages include "Cannot find module 'sanity'", "Missing peer dependency", or "Command not found: sanity".

Show original thread
20 replies
Hey Kieran! Let’s see if we can troubleshoot this. What command did you use to originally install Sanity?
Hello
user M
thanks for checking in on my problem. I used
npm install -g @sanity/cli
from inside my react project's folder
Next, I used
sanity login
for logging in followed by
sanity init
which is when the error showed up. I couldnt find any fixes yet so the whole process is on hold
During the various steps for of
sanity init
process when it starts
resolving dependencies
it throws that error
Hmm, this looks like someone who had a similar error. Try to
cd
into your project folder and run
npm install node_modules
and see if that helps.
Sure checking it out now, thanks
Doesn't seem to work sadly, Gives me another error
Just fyi, I ran
npm install
inside my project folder just now and tried
sanity init
its throwing the same error when resolving dependencies
I looks like you may have installed Sanity just as we were releasing the v2.4.0 version - sometimes the NPM registry is not fully up to date during the publishing process, which can lead to this (initial) error message.
I would try removing
node_modules
(
rm -rf node_modules
) and reinstalling dependencies (
npm install
).
Having said that, the latest error you're seeing is odd - maybe the official npm registry is having some issues? That module isn't one of "ours"...
Can you try doing the mentioned rm + npm install proceedure and see if that helps? The
sanity
command uses yarn internally instead of npm, so it might have slightly different behavior
I'm already working on it
user Z
hopefully it works this time lol. I've been stuck here all day unable to do anything with the project sighs
One of those days, eh? 😓
Yuppers 😞 It's my first ever react project and was excited to building it with sanity but here we are LOL
Sorry to hear that, let me know how the install goes :x
Ah crap! I'm now getting a whole new error with
npm install
now 🤦‍♀️
Uh. Never seen that before.The interwebs suggest
npm cache clean --force
and re-running
npm install
, but I'm on thin ice here 😅
I removed the
node-modules
again, restarted the terminal and installed npm and it worked without any errors, weird and I've run into that
cb error
before not sure how I resolved it. I'm now running
sanity init
As for the
cb() never called error
from above picture, they have a whole repo of issues from hundreds of folx and seems its unique to every single occurence and there's a whole lot of steps to reproduce the problem/error and then we gotta create a new issue on their repo and wait patiently for a fix, which could happen all over again lol
user Z
It actually went through this time and its working. Sorry took me a while to let ya know, I've got a slow connection here. I still have no idea why that even happened, apparently its something I deal with every time I either create a new react-app or something new related to npm.
It's working now though. Thanks for your help and
user M
, appreciate it
Sounds frustrating! I’m glad it worked out now though!

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?