Node.js update resolves error after Sanity upgrade in Slack thread

4 replies
Last updated: Apr 22, 2025
Hey everyone,
Just tried to update sanity using
yarn upgrade
and now getting this error when trying to run `yarn dev`:
yarn dev
yarn run v1.22.17
$ sanity dev
✓ Checking configuration files...
⠸ Starting dev server
TypeError: crypto$2.getRandomValues is not a function
    at resolveConfig (file:///C:/rb_repos/learning-cms/node_modules/vite/dist/node/chunks/dep-DG3BLbPj.js:48961:16)
    at async _createServer (file:///C:/rb_repos/learning-cms/node_modules/vite/dist/node/chunks/dep-DG3BLbPj.js:38255:18)
    at async startDevServer (C:/rb_repos/learning-cms/node_modules/sanity/lib/_chunks-cjs/devAction2.js:65:38)
    at async startSanityDevServer (C:/rb_repos/learning-cms/node_modules/sanity/lib/_chunks-cjs/devAction2.js:160:5)
error Command failed with exit code 1.
info Visit <https://yarnpkg.com/en/docs/cli/run> for documentation about this command.
Any thoughts or ideas?

Running node v16.20.0
AI Update

The error you're encountering is happening because you're running Node.js v16.20.0, but current versions of Sanity Studio require Node.js 18 or higher (and as of Studio v4, Node.js 20+ is required).

The crypto$2.getRandomValues is not a function error is a symptom of Vite (which Sanity Studio uses under the hood) trying to use crypto APIs that aren't available or are implemented differently in older Node.js versions.

Solution

You need to upgrade your Node.js version. Here's what to do:

  1. Install Node.js 20 or higher (recommended to use the latest LTS version)

    • Download from nodejs.org
    • Or use a version manager like nvm (recommended for managing multiple Node versions)
  2. Verify your Node version after installation:

    node -v

    You should see v20.x.x or higher

  3. Reinstall your dependencies:

    yarn install
  4. Try running dev again:

    yarn dev

Why This Happened

When you ran yarn upgrade, it updated Sanity packages to newer versions that require Node.js 20+. As explained in Sanity's blog post about Studio v4, this requirement was introduced because Node.js 18 reached end-of-life in April 2024, and the upgrade allows Sanity to use modern tooling like Vite 7 for faster builds and better performance.

The good news is that once you upgrade Node.js, everything should work smoothly!

What was your previous sanity version prior to your latest upgrade, and what is your current version? The first thing I can think of is that later versions of sanity may need higher versions of node. I'd recommend installing something in the range of 18 and above and see what happens.
Looks like the solution was to update Node.js
Oh nice! Glad you figured it out.
I was trying things still and just updated everything and it worked!

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?