Can't resolve react-icons after Sanity upgrade

6 replies
Last updated: Feb 17, 2021
I just upgraded Sanity, and I get compilation errors for all the react icons, e.g. :
Error: Can't resolve 'react-icons/lib/io/android-color-palette'.
Can these not be used anymore?
AI Update

This issue is actually not Sanity-specific—it's related to react-icons v4 breaking changes where deep import paths like 'react-icons/lib/io/android-color-palette' were removed.

The react-icons library deprecated and removed support for deep imports from the /lib directory in version 4. Previously, you could import icons using paths like:

import Icon from 'react-icons/lib/io/android-color-palette'

But this no longer works. The library now requires you to import icons using the top-level icon set imports with proper component names:

import { IoAndroidColorPalette } from 'react-icons/io'

How to fix this:

  1. Find the correct icon component name: The path android-color-palette becomes IoAndroidColorPalette in camelCase with the icon set prefix (Io for Ionicons)

  2. Update your imports: Change from deep imports to named imports from the icon set:

    // Old (broken):
    import Icon from 'react-icons/lib/io/android-color-palette'
    
    // New (correct):
    import { IoAndroidColorPalette } from 'react-icons/io'
  3. Common icon set prefixes:

    • react-icons/ioIo prefix (Ionicons)
    • react-icons/faFa prefix (Font Awesome)
    • react-icons/mdMd prefix (Material Design)
    • react-icons/hiHi prefix (Heroicons)
    • react-icons/aiAi prefix (Ant Design)
    • react-icons/bsBs prefix (Bootstrap)

If you're using these icons in Sanity Studio schema definitions (like for document type icons), the same fix applies—just update the import path and use the named export:

// In your schema file
import { IoAndroidColorPalette } from 'react-icons/io'

export default {
  name: 'myDocumentType',
  type: 'document',
  icon: IoAndroidColorPalette,
  // ...
}

Why this happened: When you upgraded Sanity, it likely updated your dependencies including react-icons to v4+, which introduced this breaking change. The library maintainers removed deep imports to improve tree-shaking and bundle sizes.

You can absolutely still use react-icons—you just need to update your import statements to the new format! The icons themselves haven't been removed, just the way you import them has changed.

Show original thread
6 replies
Hi User, you might have upgraded from a version before
2.0.1
in this case, where we removed our own use (and therefore the dependency) of
react-icons
in the studio.
If you scroll down to the
Breaking changes header on this page, you should find instructions on how to fix the issue either by adding v2 of
react-icons
as a dependency or by upgrading to v3 and updating the import statements: https://github.com/sanity-io/sanity/releases/tag/v2.0.1
Yes, I did upgrade from a version before 2.0.1. I will take a look at the link. Thank you for the fast reply! 👍😀
I updatd icons to v3, then ran
npm install --global @sanity/cli
then ran

sanity codemod reactIconsv3
but I get:

@sanity/core not installed in current project
`Project-specific commands not available until you run `sanity install``
Do I still need to do some updates?
You may have to run
sanity install
before running the codemod, but that should be all 🙂
Hehe, my brain though I had already run the sanity install....now I ran it for real.... almost there... Now when running the
codemode
command I get

events.js:167

throw er; // Unhandled 'error' event

^


Error: spawn npx ENOENT

at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19)

at onErrorNT (internal/child_process.js:407:16)

at process._tickCallback (internal/process/next_tick.js:63:19)

Emitted 'error' event at:

at Process.ChildProcess._handle.onexit (internal/child_process.js:238:12)

at onErrorNT (internal/child_process.js:407:16)

at process._tickCallback (internal/process/next_tick.js:63:19)

I do not have an events.js file in my project...
I ended up changing the import paths manually. But now it works.

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?