useRootTheme() missing context value error after upgrading to v2.2.4

4 replies
Last updated: Jan 27, 2021
Hi! Upgrading to the newest version 2.2.4 (and 0.33.0 for
@sanity/ui
) crashes the studio with this error:
useRootTheme(): missing context value
. I tried deleting
package-lock.json
and reinstalling all dependencies, but it didn't help!
AI Update

The useRootTheme(): missing context value error you're experiencing is typically related to multiple versions of @sanity/ui being installed in your dependency tree. This happens when React Context from one version of @sanity/ui can't find the provider from another version, even though they might be the same version number but installed in different locations.

Potential Solutions to Try

Since you've already tried deleting package-lock.json and reinstalling, here are some additional approaches:

1. Force a Single Version Using Package Resolutions

Add an overrides field to your package.json to ensure all dependencies use the same version of @sanity/ui:

For npm (v8.3+):

{
  "overrides": {
    "@sanity/ui": "0.33.0"
  }
}

For yarn:

{
  "resolutions": {
    "@sanity/ui": "0.33.0"
  }
}

After adding this, remove everything and reinstall:

rm -rf node_modules package-lock.json
npm install

2. Check for Duplicate Installations

Verify if multiple versions are installed:

npm ls @sanity/ui

This will show you the dependency tree and reveal if multiple copies exist.

3. Try Switching Package Managers

Based on Sanity community discussions, some developers have resolved similar @sanity/ui issues by switching between npm and yarn. If you're using npm, try yarn (or vice versa).

4. Clear All Caches

Sometimes cached builds can cause issues:

rm -rf node_modules package-lock.json .sanity
npm cache clean --force
npm install

Why This Happens

React Context requires that the provider and consumer come from the exact same module instance. When multiple copies of @sanity/ui exist (common with plugins that also depend on it), React treats them as separate contexts, causing the "missing context value" error.

If none of these solutions work, you might want to check if any of your installed Sanity plugins have peer dependency conflicts with the versions you're using, or consider reporting the specific version combination issue to Sanity support with your full dependency tree.

Show original thread
4 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.

Was this answer helpful?