Phosphor React Icons
Phosphor React is a comprehensive icon library for React applications, providing a flexible and visually consistent icon family. The current stable version is 2.1.10, actively maintained with frequent minor and patch releases that add new icons, features, and bug fixes. Key differentiators include six distinct weights (thin, light, regular, bold, fill, duotone) for stylistic versatility, robust support for React Context to manage global icon styling, and full compatibility with standard SVG properties. The library is tree-shaking friendly, ensuring optimal bundle sizes, and offers official support for React Server Components (RSC) and server-side rendering (SSR) via a dedicated submodule. It also integrates JSDoc icon previews for enhanced developer experience.
Common errors
-
Named export 'Envelope' not found. The requested module '@phosphor-icons/react' is a CommonJS module, which may not support all module.exports as named exports.
cause Attempting to import named exports from `@phosphor-icons/react` in a context where the bundler or runtime treats it as a CommonJS module, or an older bundler struggles with its ESM nature.fixEnsure your project's bundler is configured to correctly handle ES Modules. If encountering this in Node.js, ensure your package.json has `"type": "module"` or use a transpiler. Sometimes `import pkg from '@phosphor-icons/react'; const { Envelope } = pkg;` can be a workaround for specific bundler issues, but it's not the recommended long-term solution. Upgrade to `@phosphor-icons/react@^2.1.10`. -
Property 'children' does not exist on type 'IntrinsicAttributes & SVGProps<SVGSVGElement> & IconProps'
cause Type incompatibility between `@phosphor-icons/react`'s internal types and an outdated `@types/react` dependency in your project.fixUpdate `@types/react` to the latest compatible version using `npm install @types/react@latest` or `yarn upgrade @types/react`. This specific issue was addressed and fixed in `v2.1.7`. -
Module not found: Can't resolve '@phosphor-icons/react'
cause The package `@phosphor-icons/react` is not installed, or the import path is incorrect, or the old package name `phosphor-react` is still being used.fixVerify the package is installed with `npm install @phosphor-icons/react` or `yarn add @phosphor-icons/react`. Double-check the import statements to ensure they use `@phosphor-icons/react` as the package name, not `phosphor-react`.
Warnings
- breaking The package name was changed from `phosphor-react` to `@phosphor-icons/react` in v2. Importing from the old package name will result in using an older, unmaintained version and will not receive new icons or updates.
- deprecated As of `v2.1.8`, all exported icon components are suffixed with the word 'Icon' (e.g., `UserIcon`). While old names (e.g., `User`) are still valid, they are marked as deprecated to improve readability and prevent name collisions.
- gotcha When using Phosphor Icons within React Server Components (RSC) or environments that do not permit the Context API (like Next.js Server Components), icons must be imported from the `@phosphor-icons/react/ssr` submodule. These SSR variants do not support `IconContext` inheritance.
- gotcha Early v2 versions (before `v2.1.10`) sometimes encountered module resolution issues, especially in mixed ESM/CJS environments, potentially leading to errors like `ReferenceError: exports is not defined` or `SyntaxError: Cannot use import statement outside a module`.
- gotcha `v2.1.0` through `v2.1.4` briefly switched to a modern JSX runtime, causing compatibility issues with `react@16` applications. This was reverted in `v2.1.5` to restore React 16 support.
Install
-
npm install phosphor-react -
yarn add phosphor-react -
pnpm add phosphor-react
Imports
- HeartIcon
import { Heart } from 'phosphor-react'import { HeartIcon } from '@phosphor-icons/react' - IconContext
import { IconContext } from 'phosphor-react'import { IconContext } from '@phosphor-icons/react' - FishIcon
import { FishIcon } from '@phosphor-icons/react'import { FishIcon } from '@phosphor-icons/react/ssr'
Quickstart
import React from 'react';
import ReactDOM from 'react-dom/client';
import { IconContext, HorseIcon, HeartIcon, CubeIcon } from '@phosphor-icons/react';
const App = () => {
return (
<IconContext.Provider
value={{
color: 'limegreen',
size: 32,
weight: 'bold',
mirrored: false,
}}
>
<div style={{ padding: '20px', fontFamily: 'sans-serif' }}>
<h1>My Awesome Icons</h1>
<p>Icons inheriting context defaults:</p>
<HorseIcon /> {/* Will be lime-green, 32px, and bold! */}
<HeartIcon /> {/* Me too! */}
<CubeIcon /> {/* Me three :) */}
<p>Icons with overridden props:</p>
<HeartIcon color="#AE2983" weight="fill" size={48} />
<CubeIcon color="teal" weight="duotone" mirrored={true} />
</div>
</IconContext.Provider>
);
};
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(<App />);