
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThis error is a classic dependency version mismatch issue between @sanity/ui and other Sanity packages after running sanity upgrade. The useMediaIndex export error indicates that you have incompatible versions of Sanity packages installed, where @sanity/ui is trying to import a hook that doesn't exist in the version of its internal dependencies.
Here's how to fix it:
Delete your node_modules and lockfile:
rm -rf node_modules
rm package-lock.json # or yarn.lock / pnpm-lock.yamlReinstall dependencies:
npm install # or yarn / pnpm installRestart the dev server:
sanity startCheck for version mismatches in your package.json. All @sanity/* packages should be on compatible versions. The issue typically happens when:
@sanity/ui is on a different major/minor version than expected by @sanity/base or sanitynpm list @sanity/ui)Force align versions by running:
npm install @sanity/ui@latest sanity@latestOr if you're on Studio v2 (which appears to be the case based on @sanity/base in your error), ensure all your @sanity/* packages are on compatible v2 versions. You might need to explicitly install matching versions:
npm install @sanity/ui@^0.x @sanity/base@^2.x(Replace x with the appropriate minor versions that are compatible)
The sanity upgrade command sometimes doesn't upgrade all interdependent packages consistently, especially when there are peer dependency conflicts or when npm/yarn's resolution algorithm picks incompatible versions. The useMediaIndex hook was likely added/moved/removed between versions of @sanity/ui, and your installation has mismatched versions.
When upgrading Sanity:
node_modules and lockfiles after upgrading@sanity/* packages in package.json are on compatible versionsnpm list @sanity/ui to verify what version is actually installedIf you continue having issues after trying these steps, check your package.json for any version pinning (~ or exact versions) that might be preventing proper upgrades, and consider sharing your package versions for more specific troubleshooting help.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store