Troubleshooting
Sprite file not emitted / icons not rendering
Symptom: The build succeeds with no errors, but sprite.svg is not in the output directory and SVG icons do not render.
Cause: The built-in asset module handling is intercepting .svg files before the loader runs.
Fix: Add type: 'javascript/auto' to your SVG rule:
Warning: "SvgSpritePlugin is registered but no SVG symbols were collected"
The plugin is in your plugins array but no SVGs went through the loader. Common causes:
- Missing
type: 'javascript/auto'on the loader rule. include/excludefilters on the rule do not match your SVG file paths.- No SVG imports in your code. At least one
.svgfile must be imported.
Warning: "Extract mode is enabled but SvgSpritePlugin was not found"
The loader runs in extract mode (extract: true) but SvgSpritePlugin is not in the plugins array:
Icon is a broken image, or DevTools shows data:image/svg+xml;base64
Cause: Another rule (your own image rule, or a framework default) assigns an asset module type to .svg files. The sprite loader still runs, but its JavaScript output is emitted as the image instead of being executed.
Fix: The loader prints a build warning that names the file and the module type, for example ... is handled as module type "asset/inline". Add type: 'javascript/auto' to the rule that uses rspack-plugin-svg-sprite/loader, or exclude your icon folder from the other rule.
Icons vanish from the extracted sprite during development, or after a cached rebuild
Cause: Versions up to 1.5.2 let the bundler cache SVG modules in extract mode. A cached module skips the loader, so its symbol was never registered with the plugin.
Fix: Upgrade to 1.5.3 or newer. In extract mode the loader now opts out of caching.
Two icons show the same gradient, clip path, or class styling
Cause: All symbols live in one SVG document. Icons minified by SVGO often reuse ids such as id="a", and Illustrator exports reuse class names such as .cls-1. The first definition in the document wins.
Fix: Let SVGO prefix ids and class names per file before the sprite loader runs:
Loaders run from the last entry to the first, so SVGO processes the raw SVG and the sprite loader receives the result.
An icon is scaled differently after upgrading from 1.5.2 or older
Older versions lowercased attribute names on the root <svg>, which turned preserveAspectRatio into an attribute browsers ignore. The attribute is now kept as written. If you preferred the old rendering, remove preserveAspectRatio from the source SVG.
Known limitations
- An SVG with no
viewBoxand no numericwidthandheightgetsviewBox="0 0 24 24". The build prints a warning that names the file. Add aviewBox(or numericwidthandheight) to the root<svg>if that is not its real size. spriteFilenameis used literally. Placeholders such as[hash]or[chunkname]are not interpolated.- The Rsbuild plugin replaces Rsbuild's built-in SVG rule.
./icon.svg?url,?inlineand?rawtherefore also return a sprite symbol, and SVGs outside the plugin'sinclude/excludescope are left without Rsbuild's default handling. - In extract mode, Safari (WebKit) does not resolve
url(#id)references inside an external sprite file. An icon that uses a gradient, pattern, filter, mask or clip-path paints blank there. Chrome and Firefox are not affected. Use inline mode for those icons, or flatten the effect to solid fills. - An entity declared in an SVG's DOCTYPE (
<!ENTITY fill "red">, used as&fill;) is not expanded. The build prints a warning that names the file and the entity. Replace the entity with its literal value in the file, or run SVGO, which expands entities. - The icon id is the file name.
icon.idis that name as written. In the markup (icon.contentand the extracted sprite) the characters&,<and"are escaped, soQ&A.svgis written as<symbol id="Q&A">. Inicon.urlthe id is used raw, except that a%followed by two hex digits is written as%25. Control characters other than tab, newline and carriage return cannot be written in XML, so avoid them in file names.
Still stuck?
Search or ask in Discussions, or report a bug. A minimal reproduction helps: fork the StackBlitz starter.