Documentation Index Fetch the complete documentation index at: https://mintlify.com/react-icons/react-icons/llms.txt
Use this file to discover all available pages before exploring further.
Troubleshooting Guide
Find solutions to common problems when using React Icons.
Installation Issues
Package Installation Fails
npm install fails with permission errors
Problem: Permission denied errors when installingSolution: # Don't use sudo with npm
# Instead, fix npm permissions:
npm config set prefix ~/.npm-global
export PATH =~ /. npm-global / bin : $PATH
# Then install normally
npm install react-icons
Or use a version manager like nvm .
Yarn install fails with network errors
Problem: Network timeouts or connection errorsSolution: # Try with different registry
yarn add react-icons --registry https://registry.npmjs.org
# Or clear cache and retry
yarn cache clean
yarn add react-icons
Module not found after installation
Problem: Cannot find module 'react-icons'Solution:
Verify installation:
ls node_modules/react-icons
If missing, reinstall:
rm -rf node_modules package-lock.json
npm install
Check import path:
// ✅ Correct
import { FaBeer } from "react-icons/fa" ;
// ❌ Wrong
import { FaBeer } from "react-icons" ;
Import & Build Issues
Icons Not Rendering
Icons show as empty elements
Problem: Icons don’t appear but no errors in consoleDiagnosis: import { FaBeer } from "react-icons/fa" ;
console . log ( FaBeer ); // Should log a function
console . log ( typeof FaBeer ); // Should be "function"
Solutions:
Check import syntax:
// ✅ Correct
import { FaBeer } from "react-icons/fa" ;
// ❌ Wrong
import FaBeer from "react-icons/fa/FaBeer" ;
Verify icon name is correct:
// Check icon exists
import * as FaIcons from "react-icons/fa" ;
console . log ( Object . keys ( FaIcons )); // List all available icons
Ensure React is imported:
import React from "react" ; // Required in older React versions
import { FaBeer } from "react-icons/fa" ;
SVG not visible (size is 0)
Problem: Icon renders but has no sizeSolution: // Set explicit size
< FaBeer size = { 24 } />
// Or use CSS
< FaBeer style = { { width: 24 , height: 24 } } />
< FaBeer className = "w-6 h-6" />
Icons default to 1em - ensure parent has font-size set: .parent {
font-size : 16 px ; /* Icons will be 16px */
}
Bundle Size Issues
Problem: Bundle includes many unused iconsDiagnosis: Analyze your bundle: # For Create React App
npm install --save-dev source-map-explorer
npm run build
npx source-map-explorer 'build/static/js/*.js'
# For Next.js
npm install --save-dev @next/bundle-analyzer
Common causes & fixes:
Importing entire library:
// ❌ Wrong - imports everything (~2MB)
import * as Icons from "react-icons/fa" ;
// ✅ Correct - only imports needed icons
import { FaBeer , FaCoffee } from "react-icons/fa" ;
Dynamic imports with wildcard:
// ❌ Wrong
const icon = Icons [ `Fa ${ iconName } ` ];
// ✅ Better - explicit mapping
const iconMap = {
beer: FaBeer ,
coffee: FaCoffee
};
const Icon = iconMap [ iconName ];
Bundler not tree-shaking:
Webpack 5: module . exports = {
mode: 'production' ,
optimization: {
usedExports: true ,
sideEffects: false
}
};
Vite - works by defaultCreate React App - works by default in production buildsSee Performance Optimization for more tips.
Problem: All icons from a pack are includedCheck:
Using production build:
# Development builds don't tree-shake
NODE_ENV = production npm run build
Module format:
{
"type" : "module" // Helps with tree-shaking
}
Bundler configuration:
For Webpack: module . exports = {
optimization: {
usedExports: true ,
},
};
Import from correct path:
// ✅ ES module path (tree-shakeable)
import { FaBeer } from "react-icons/fa" ;
// ❌ CommonJS path (not tree-shakeable)
const { FaBeer } = require ( "react-icons/fa" );
TypeScript Issues
Type errors with icon imports
Problem: TypeScript can’t find typesSolution:
Remove conflicting types:
npm uninstall @types/react-icons
React Icons v3+ includes native TypeScript support.
Update TypeScript:
npm install --save-dev typescript@latest
Requires TypeScript 4.0+
Check tsconfig.json:
{
"compilerOptions" : {
"esModuleInterop" : true ,
"moduleResolution" : "node"
}
}
Problem: IconType type errorsSolution: import { IconType } from "react-icons" ;
type Props = {
icon : IconType ; // ✅ Correct
size ?: number ;
};
function IconWrapper ({ icon : Icon , size } : Props ) {
return < Icon size = { size } /> ;
}
Make sure to destructure and capitalize: // ✅ Correct - Icon is capitalized
const { icon : Icon } = props ;
return < Icon /> ;
// ❌ Wrong - lowercase won't work
const { icon } = props ;
return < icon /> ; // Error: 'icon' is not a JSX component
Type 'Element' is not assignable to type 'ReactNode'
Problem: Type mismatch in strict modeSolution: import { ReactElement } from "react" ;
import { IconType } from "react-icons" ;
type Props = {
icon : IconType ;
};
function Component ({ icon : Icon } : Props ) : ReactElement {
return < Icon /> ;
}
Framework-Specific Issues
Next.js
Icons not rendering in Next.js App Router
Problem: Icons don’t show in Server ComponentsSolution: Icons work in Server Components, but IconContext needs Client Component: "use client" ;
import { IconContext } from "react-icons" ;
export function IconProvider ({ children }) {
return (
< IconContext.Provider value = { { size: "1.5em" } } >
{ children }
</ IconContext.Provider >
);
}
import { IconProvider } from "./icon-provider" ;
export default function RootLayout ({ children }) {
return (
< html >
< body >
< IconProvider > { children } </ IconProvider >
</ body >
</ html >
);
}
Build fails with 'Cannot find module'
Problem: Next.js build fails importing iconsSolution:
Check Next.js version:
Requires Next.js 12+
Verify import paths:
// ✅ Correct
import { FaBeer } from "react-icons/fa" ;
// ❌ Wrong - don't import from lib/
import { FaBeer } from "react-icons/lib/fa" ;
Create React App
Icons not updating after build
Problem: Changes to icons don’t reflect in buildSolution: # Clear cache and rebuild
rm -rf node_modules/.cache
npm run build
Vite
Problem: Failed to resolve importSolution: Vite works with React Icons by default. If you see errors: import { defineConfig } from 'vite' ;
import react from '@vitejs/plugin-react' ;
export default defineConfig ({
plugins: [ react ()] ,
optimizeDeps: {
include: [ 'react-icons' ] // Pre-bundle react-icons
}
}) ;
Styling Issues
Icons misaligned with text
Problem: Icons don’t align vertically with textSolution: React Icons v3+ removed automatic alignment. Add it back: // Global fix
import { IconContext } from "react-icons" ;
< IconContext.Provider value = { { style: { verticalAlign: 'middle' } } } >
< YourApp />
</ IconContext.Provider >
// Per icon
< FaBeer style = { { verticalAlign: 'middle' } } />
/* CSS class */
.icon {
vertical-align : middle ;
}
See Migration v2 to v3 for details.
Icons don't respond to color prop
Problem: Color prop doesn’t workCheck:
Not using multiColor icons:
// Flat Color Icons preserve original colors
import { FcIdea } from "react-icons/fc" ;
< FcIdea color = "red" /> { /* Won't work - colors are fixed */ }
CSS specificity:
/* Overly specific CSS */
svg path {
fill : blue !important ; /* Overrides color prop */
}
Solution: // Use currentColor
< div style = { { color: "red" } } >
< FaBeer /> { /* Inherits red */ }
</ div >
Tailwind classes not working
Problem: Tailwind CSS classes have no effectSolution: // Size classes need to be explicit
< FaBeer className = "w-6 h-6" /> { /* ✅ Works */ }
// Or use size prop
< FaBeer size = { 24 } className = "text-blue-500" /> { /* ✅ Works */ }
Note: Tailwind’s size utilities override the icon’s default 1em size.
Context API Issues
IconContext not applying styles
Problem: Context values don’t affect iconsCheck:
Icons are inside Provider:
import { IconContext } from "react-icons" ;
// ✅ Correct
< IconContext.Provider value = { { color: "blue" } } >
< FaBeer /> { /* Will be blue */ }
</ IconContext.Provider >
// ❌ Wrong - icon outside provider
< FaBeer /> { /* Won't be blue */ }
< IconContext.Provider value = { { color: "blue" } } >
{ children }
</ IconContext.Provider >
Props override context:
< IconContext.Provider value = { { color: "blue" } } >
< FaBeer color = "red" /> { /* Will be red, not blue */ }
</ IconContext.Provider >
Nested contexts not working correctly
Problem: Inner context doesn’t override outerExpected behavior: < IconContext.Provider value = { { color: "blue" , size: 24 } } >
< FaBeer /> { /* blue, size 24 */ }
< IconContext.Provider value = { { color: "red" } } >
< FaCoffee /> { /* red, size 24 (size inherited) */ }
</ IconContext.Provider >
</ IconContext.Provider >
Inner contexts merge with outer contexts, with inner values taking precedence.
Error Messages
Warning: React does not recognize prop
Problem: Warning: React does not recognize the 'size' prop on a DOM elementCause: Passing icon props to wrong elementSolution: // ❌ Wrong - size on div
< div size = { 24 } >
< FaBeer />
</ div >
// ✅ Correct - size on icon
< div >
< FaBeer size = { 24 } />
</ div >
Problem: Error: Element type is invalid: expected a string or a class/functionCause: Import failed or component not capitalizedSolution: import { IconType } from "react-icons" ;
import { FaBeer } from "react-icons/fa" ;
type Props = { icon : IconType };
function Component ({ icon : Icon } : Props ) {
// ✅ Correct - Icon is capitalized
return < Icon /> ;
// ❌ Wrong - lowercase
// return <icon />;
}
Getting More Help
FAQ Check frequently asked questions
GitHub Issues Search existing issues or report a bug
GitHub Discussions Ask the community for help
Stack Overflow Search or ask questions
When asking for help, include:
React Icons version (npm list react-icons)
React version
Framework (Next.js, CRA, Vite, etc.) and version
Code example showing the issue
Error messages (if any)