Troubleshooting schema extraction error in Sanity CLI version 3.45.0
The sanity schema extract command is part of the TypeGen feature, which requires Sanity CLI version 3.35.0 or later according to the official documentation. You're running version 3.45.0, which should definitely have this command, so something else is going on.
The issue is almost certainly that you have a global installation of the Sanity CLI that's outdated or conflicting with your project's local version. Even though sanity --version reports 3.45.0, the global CLI binary may not be properly updated.
Solution 1: Use npx (Recommended)
Instead of using the globally installed CLI, run the command with npx to use the latest version:
npx sanity@latest schema extractThis ensures you're using the most recent CLI version regardless of what's installed globally.
Solution 2: Update Global CLI
If you prefer using the global CLI, update it:
npm install -g @sanity/cli@latestThen verify the version:
sanity --versionSolution 3: Use Local CLI
If you have @sanity/cli installed as a project dependency, you can use it directly:
npx sanity schema extractor add it to your package.json scripts:
{
"scripts": {
"extract-schema": "sanity schema extract"
}
}Then run npm run extract-schema.
What the command does:
The sanity schema extract command generates a schema.json file containing a static representation of your Studio schema. This is typically the first step in the TypeGen workflow, which then allows you to generate TypeScript types with sanity typegen generate.
The most common cause of this error is having an outdated global CLI installation that doesn't include the newer schema extraction feature, even though it reports a version number that should support it. Using npx sanity@latest bypasses this issue entirely and is the quickest way to get unblocked.
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.