Migrate from astro-icon
This guide walks through replacing astro-icon with astro-iconset in an existing Astro project. The two packages share a similar mental model — local SVGs, Iconify sets, an Icon component — so most of the changes are mechanical find-and-replace work.
-
Install astro-iconset and remove astro-icon
Section titled “Install astro-iconset and remove astro-icon”Terminal window npm install astro-iconsetnpm uninstall astro-iconTerminal window pnpm add astro-iconsetpnpm remove astro-iconTerminal window yarn add astro-iconsetyarn remove astro-icon -
Update
Section titled “Update astro.config.mjs”astro.config.mjsReplace the integration import and registration:
astro.config.mjs import icon from "astro-icon";import icon from "astro-iconset";export default defineConfig({integrations: [icon()],});If you had
astro-icon-specific options (such asincludefor pack filtering), check the configuration reference to confirm the equivalent option name in astro-iconset. -
Update component imports
Section titled “Update component imports”The component path changes from
astro-icon/componentstoastro-iconset/components:import { Icon } from "astro-icon/components";import { Icon } from "astro-iconset/components";This applies to every
.astrofile that importsIcon. Most editors can do a project-wide find-and-replace on the stringastro-icon/components. -
Check your
Section titled “Check your name prop values”nameprop valuesBoth packages use the same Iconify
set:icon-nameformat for Iconify icons and the same file-relative slug for local icons, sonamevalues usually do not need to change.Icon type Example value Change needed? Local SVG ( src/icons/logo.svg)name="logo"No Local SVG in subfolder ( src/icons/logos/astro.svg)name="logos/astro"No Iconify icon name="mdi:account"No -
Replace any
Section titled “Replace any Sprite or SpriteProvider usage”SpriteorSpriteProviderusageastro-icon exposed a separate
Spritecomponent or sprite-provider pattern in some versions. astro-iconset handles sprites automatically inside theIconcomponent — there is no separate wrapper to add or remove.Remove any
SpriteProviderwrappers from your layouts. TheIconcomponent itself emits<symbol>/<use>pairs when the same icon is used more than once on a page.If you ever want a fully inlined SVG without sprite behavior, add
is:inline:<Icon name="logo" is:inline /> -
Switch framework-component icons (if applicable)
Section titled “Switch framework-component icons (if applicable)”If you used
astro-iconinside React, Vue, or other framework components via a workaround, astro-iconset ships first-class adapters:src/components/Nav.tsx import { Icon } from "astro-icon/components"; // ❌ does not work in .tsximport Icon from "astro-iconset/react"; // ✓ first-class React adapterAvailable adapters:
astro-iconset/react,/vue,/svelte,/preact,/solid. See Framework islands. -
Verify your local icon directory
Section titled “Verify your local icon directory”Both packages default to
src/icons/. If you moved it withastro-icon’siconDiroption, set the same path in astro-iconset:astro.config.mjs icon({ iconDir: "src/assets/icons" })astro-iconset also supports multiple directories and named prefixes via
iconDirs— see the configuration reference. -
Run a build and check for errors
Section titled “Run a build and check for errors”Terminal window npm run buildTerminal window pnpm buildTerminal window yarn buildThe build output will report any icon names it cannot resolve. Common causes:
- A local SVG file was renamed or moved.
- An
@iconify-json/*package was removed or not yet installed. - A
namevalue still uses a format from an older astro-icon version.
What you gain
Section titled “What you gain”After migrating you get everything from astro-iconset that astro-icon does not ship:
?iconimports — import a single.svgfile as icon data anywhere in your project.- Framework adapters —
Iconthat works natively inside React, Vue, Svelte, Preact, and Solid files. - Named prefix directories (
iconDirs) — organize icon sets under custom prefixes likebrand:logo. - SSR
includefilter — ship only the icons your server actually references, not an entire Iconify set.
See Features for the full list.
Troubleshooting
Section titled “Troubleshooting”Build error: cannot find icon …
The slug does not match a local file or installed Iconify set. Check that the @iconify-json/* package is installed and the icon name is spelled correctly.
TypeScript errors on ?icon imports
Add astro-iconset/svg-icon to your compilerOptions.types or reference it in src/env.d.ts. See SVG imports.
Icons inside React / Vue / Svelte not rendering
You cannot import astro-iconset/components Icon inside framework files. Use the framework adapter (astro-iconset/react, etc.) or render Icon in an .astro wrapper and pass the result as a slot. See Framework islands.