TypeError when running `npm run dev` in a fresh install of Sanity.io
I'm sorry you're running into this error on a fresh install! That's definitely frustrating when you haven't even written any code yet.
Since this is happening on a completely fresh installation, here are the most common causes and solutions to try:
1. Check your Node.js version
Sanity Studio v4 requires Node.js version 20 or higher. If you're on an older version, this could cause unexpected errors. Check your version with:
node -vIf you're below Node 20, upgrade to the latest LTS version and try again.
2. Clear your dependency cache and reinstall
Sometimes package installations can get corrupted or have conflicts. Try a clean reinstall:
# Delete node_modules and lock file
rm -rf node_modules
rm package-lock.json # or yarn.lock or pnpm-lock.yaml
# Clear npm cache
npm cache clean --force
# Reinstall dependencies
npm install3. Check for environment-specific issues
The toLowerCase() error often happens when code is trying to access browser APIs (like navigator) in an environment where they don't exist. This can happen if:
- You're using a package manager or Node version with compatibility issues
- There's a conflict with other global packages
- Your terminal or environment has unusual configurations
4. Try creating a new project
If the above doesn't work, try creating a completely fresh project in a new directory to rule out any local environment issues:
npm create sanity@latestFollow the prompts for a new project and see if the error persists.
5. Check what version you actually installed
Make sure you're getting the latest stable version by checking your package.json. The sanity package should be at version 3.x or 4.x (depending on when you're reading this).
If none of these solutions work, it would be helpful to share more details like:
- Your exact Node.js version
- Your package manager (npm, yarn, or pnpm) and its version
- Your operating system
- The complete error stack trace if possible
You might also want to check the Sanity GitHub issues to see if others have reported this specific error recently, or reach out in the Sanity Slack community where the team and community can help troubleshoot in real-time.
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.