Sanity init fails after updating to latest version

6 replies
Last updated: Aug 3, 2022
Hi,I was starting a new Sanity project and I updated my Sanity beforehand. Now I’m getting errors when I run Sanity init. I tried using different project names, different types of datasets (no data, movie, …) and nothing works. Screenshot of the terminal here.
AI Update

I understand you're hitting errors with sanity init after updating Sanity. Without seeing the specific error in your screenshot, the most likely culprit is Node.js version compatibility.

Check Your Node.js Version First

Sanity Studio v4 requires Node.js 20 or higher. This is a hard requirement introduced because Node.js 18 reached end-of-life in April 2024. Check your current version:

node -v

If you're on Node 18 or lower, that's almost certainly causing your sanity init failures. You'll need to upgrade to Node.js 20 or higher.

Why This Matters

When you updated Sanity with npm install --global sanity@latest, you likely pulled down Sanity v4, which won't run on older Node versions. The error might manifest as cryptic messages like crypto$2.getRandomValues is not a function or other initialization failures, regardless of which project name or dataset type you choose.

After Upgrading Node

Once you're on Node 20+, try sanity init again. The command should work normally and walk you through:

  • Creating or selecting a Sanity project
  • Setting up your dataset
  • Choosing a project template

Alternative Installation Methods

If you continue having issues after confirming Node 20+:

  1. Clear npm cache: npm cache clean --force
  2. Reinstall Sanity CLI globally: npm install --global sanity@latest
  3. Try with npx (doesn't require global install): npx sanity@latest init

Common Related Issues

The Node.js 20+ requirement is the only breaking change in Sanity Studio v4. If you have an existing v3 studio, the upgrade requires no code changes—just the Node version bump. This is why the version went from v3 to v4 despite no API changes: dropping Node version support is technically a breaking change under semantic versioning.

The fact that you're getting errors with different project names and dataset types points to an environmental issue (like Node version) rather than a configuration problem. Once your Node version is compatible, sanity init should work as expected.

Show original thread
6 replies
Hey
user M
! What does the rest of the error look like in your terminal?
that’s the entire error
Can you paste your error instead of using a screen shot?
janne@Users-MBP Developer % npm install -g @sanity/clinpm WARN config global
--global
,
--local
are deprecated. Use
--location=global
instead.
changed 1 package, and audited 2 packages in 3s

found
0 vulnerabilitiesjanne@Users-MBP Developer % sanity init
You’re setting up a
Sanity.io project!We’ll make sure you’re logged in with
Sanity.io .Then, we’ll install a Sanity Studio for your project.

Press ctrl + C at any time to quit.

Looks like you already have a Sanity-account. Sweet!

?
Select project to use Create new project?
Your project name: FormsYour content will be stored in a dataset that can be public or private, depending on
whether you want to query your content with or without authentication.
The default dataset configuration has a public dataset named “production”.
?
Use the default dataset configuration? No?
Name of your first dataset: production?
Choose dataset visibility – this can be changed later Private (authenticated requests only)Please note that while documents are private, assets (files and images) are still public


✔️ Creating dataset?
Project output path: /Users/janne/Developer/forms?
Select project template Movie project (schema + sample data)?
Add a sampling of sci-fi movies to your dataset on the hosted backend? Yes
✔️ Bootstrapping files from template
✔️ Resolving latest module versions
✔️ Creating default project files
✖️ Resolving dependencies
Error: Command failed :(
at ~/.nvm/versions/node/v16.14.0/lib/node_modules/@sanity/cli/bin/sanity-cli.js
:3614:2582 at processTicksAndRejections (node
:internal/process/task_queues:96:5) at async e.default (~/.nvm/versions/node/v16.14.0/lib/node_modules/@sanity/cli/bin/sanity-cli.js
:4884:10714)
I think it might have created some files in that folder already, could you try running
npm install
in
/Users/janne/Developer/forms
and seeing if that works?
that worked indeed, thanks

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?