Skip to main content

Troubleshooting Guide

Find solutions to common problems when using React Icons.

Installation Issues

Package Installation Fails

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.
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
Problem: Cannot find module 'react-icons'Solution:
  1. Verify installation:
ls node_modules/react-icons
  1. If missing, reinstall:
rm -rf node_modules package-lock.json
npm install
  1. Check import path:
// ✅ Correct
import { FaBeer } from "react-icons/fa";

// ❌ Wrong
import { FaBeer } from "react-icons";

Import & Build Issues

Icons Not Rendering

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:
  1. Check import syntax:
// ✅ Correct
import { FaBeer } from "react-icons/fa";

// ❌ Wrong
import FaBeer from "react-icons/fa/FaBeer";
  1. Verify icon name is correct:
// Check icon exists
import * as FaIcons from "react-icons/fa";
console.log(Object.keys(FaIcons)); // List all available icons
  1. Ensure React is imported:
import React from "react";  // Required in older React versions
import { FaBeer } from "react-icons/fa";
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: 16px;  /* 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:
  1. 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";
  1. Dynamic imports with wildcard:
// ❌ Wrong
const icon = Icons[`Fa${iconName}`];

// ✅ Better - explicit mapping
const iconMap = {
  beer: FaBeer,
  coffee: FaCoffee
};
const Icon = iconMap[iconName];
  1. Bundler not tree-shaking:
Webpack 5:
webpack.config.js
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:
  1. Using production build:
# Development builds don't tree-shake
NODE_ENV=production npm run build
  1. Module format:
package.json
{
  "type": "module"  // Helps with tree-shaking
}
  1. Bundler configuration:
For Webpack:
module.exports = {
  optimization: {
    usedExports: true,
  },
};
  1. 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

Problem: TypeScript can’t find typesSolution:
  1. Remove conflicting types:
npm uninstall @types/react-icons
React Icons v3+ includes native TypeScript support.
  1. Update TypeScript:
npm install --save-dev typescript@latest
Requires TypeScript 4.0+
  1. 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
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

Problem: Icons don’t show in Server ComponentsSolution:Icons work in Server Components, but IconContext needs Client Component:
app/icon-provider.jsx
"use client";
import { IconContext } from "react-icons";

export function IconProvider({ children }) {
  return (
    <IconContext.Provider value={{ size: "1.5em" }}>
      {children}
    </IconContext.Provider>
  );
}
app/layout.jsx
import { IconProvider } from "./icon-provider";

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <IconProvider>{children}</IconProvider>
      </body>
    </html>
  );
}
Problem: Next.js build fails importing iconsSolution:
  1. Check Next.js version:
npm install next@latest
Requires Next.js 12+
  1. 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

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:
vite.config.js
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

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.
Problem: Color prop doesn’t workCheck:
  1. 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 */}
  1. CSS specificity:
/* Overly specific CSS */
svg path {
  fill: blue !important;  /* Overrides color prop */
}
Solution:
// Use currentColor
<div style={{ color: "red" }}>
  <FaBeer />  {/* Inherits red */}
</div>
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

Problem: Context values don’t affect iconsCheck:
  1. 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>
  1. Props override context:
<IconContext.Provider value={{ color: "blue" }}>
  <FaBeer color="red" />  {/* Will be red, not blue */}
</IconContext.Provider>
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

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)