Sanity upgrade error: "useMediaIndex was not found" in @sanity/ui

2 repliesLast updated: Nov 29, 2025

Hello. After I did sanity upgrade, I'm getting the following warning on running sanity start:

Warning in ./node_modules/@sanity/ui/dist/es/utils/layer/layerProvider.js
11:30-43 "export 'useMediaIndex' was not found in 
'../../hooks'
 @ ./node_modules/@sanity/ui/dist/es/utils/layer/layerProvider.js
 @ ./node_modules/@sanity/ui/dist/es/utils/layer/index.js
 @ ./node_modules/@sanity/ui/dist/es/utils/index.js
 @ ./node_modules/@sanity/ui/dist/es/index.js     
 @ ./node_modules/@sanity/base/lib/components/SanityRoot.js (part:@sanity/base/sanity-root)
 @ ./node_modules/@sanity/server/lib/browser/entry-dev.js
 @ multi ./node_modules/normalize.css/normalize.css ./node_modules/@sanity/server/lib/browser/entry-dev.js
It still starts the studip, but crashes again when trying to open in the browser.

Console shows the following error:


Uncaught TypeError: Object(...) is not a function
    at LayerProvider (layerProvider.js:11)
    at renderWithHooks (react-dom.development.js:14804)
    at mountIndeterminateComponent (react-dom.development.js:17483)
    at beginWork (react-dom.development.js:18597)
    at HTMLUnknownElement.callCallback (react-dom.development.js:189)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:238)
    at invokeGuardedCallback (react-dom.development.js:293)
    at beginWork$1 (react-dom.development.js:23204)
    at performUnitOfWork (react-dom.development.js:22155)
    at workLoopSync (react-dom.development.js:22131)

react-dom.development.js:19528 The above error occurred in the <LayerProvider> component:
    in LayerProvider (created by AppProvider)
    in PortalProvider (created by AppProvider)
    in UserColorManagerProvider (created by AppProvider)
    in AppProvider (created by SanityRoot)
    in Ge (created by ThemeProvider)
    in ThemeProvider (created by SanityRoot)
    in ZIndexProvider (created by SanityRoot)
    in SanityRoot
    in AppContainer

React will try to recreate this component tree from scratch using the error boundary you provided, AppContainer.
AI Update

This 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:

Quick Fix

If that doesn't work:

Check for version mismatches in your package.json. All @sanity/* packages should be on compatible versions. The issue typically happens when:

Force align versions by running:

npm install @sanity/ui@latest sanity@latest

Or 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)

Root Cause

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.

Prevention

When upgrading Sanity:

If 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.

Show original thread
2 replies

Was this answer helpful?

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.

Related contributions