Sanity Studio login screen source context error on dev and production
The "Could not find source context" error on the Sanity Studio login screen is typically a dependency or build issue. Based on the GitHub discussion, here are the most common solutions:
Quick Fixes
1. Clean install your dependencies (most common fix):
rm -rf node_modules
rm package-lock.json # or yarn.lock / pnpm-lock.yaml
npm installThis resolves most cases where the error appears during development or build. Something often gets out of sync during upgrades, especially when migrating between major versions.
2. Pin your Sanity package versions:
Remove carets from your package.json to ensure exact version matching:
{
"dependencies": {
"sanity": "3.x.x", // instead of "^3.x.x"
"@sanity/vision": "3.x.x"
}
}3. Update @sanity/vision: If you're using the Vision plugin, make sure it's on the latest version that matches your Studio version. Version mismatches here can cause context errors.
What's Happening
This error occurs when a component tries to use Sanity's internal React context (like useClient, useDataset, or useSource hooks) but can't find the context provider. This usually means:
- Mismatched package versions between
sanitycore and plugins - Duplicate React instances in your node_modules
- Corrupted dependency tree from a partial upgrade
The error shows up at login because that's when Studio components first try to access the Sanity client configuration through React context.
If You're Migrating from v2 to v3
Make sure all your @sanity/* packages are on v3 versions. Mixed v2/v3 packages will definitely cause this error. Check your package.json for any stragglers.
After cleaning dependencies, restart your dev server completely - sometimes the build cache needs clearing too. If you're still stuck after trying these steps, sharing your package.json dependencies would help diagnose further!
Show original thread10 replies
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.