Registry / rollup-plugin-svg-import
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–223 runs
build_error
glibcnode 18–223 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default export
✓ import svg from 'rollup-plugin-svg-import'
✗ const svg = require('rollup-plugin-svg-import')
Plugin is ESM-only; CommonJS require fails in Node <18 or without transpilation.
plugin usage
✓ import svg from 'rollup-plugin-svg-import'; export default { plugins: [svg()] }
✗ import { svg } from 'rollup-plugin-svg-import'
The default export is the plugin factory function, not a named export.
imported SVG (default behavior)
✓ import icon from './icon.svg'; document.body.appendChild(icon())
✗ import icon from './icon.svg'; document.body.appendChild(icon)
By default, the default export of an SVG file is a function that returns a DOM node. Calling it creates a new node each time. With `stringify: true`, the export is a string.
imported SVG (stringify mode)
✓ import icon from './icon.svg'; document.body.innerHTML += icon
✗ import { icon } from './icon.svg'
When `stringify: true` is set in plugin options, SVG files export a string directly (no function wrapper).
Shows rollup config with conditional stringify mode and how imported SVG works in both modes.
// rollup.config.js
import svg from 'rollup-plugin-svg-import';
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'esm'
},
plugins: [
svg({
stringify: process.env.NODE_ENV === 'production'
})
]
};
// src/index.js
import icon from './icon.svg';
const svgNode = icon(); // DOM node
const svgString = icon; // string if stringify: true
Errors
Common errors & fixes
TypeError: svg is not a function
Importing the plugin as a named export instead of default.
fixChange to `import svg from 'rollup-plugin-svg-import'`.
Error [ERR_REQUIRE_ESM]: require() of ES Module
Using require() on an ESM-only package.
fixUse import syntax or set { type: 'module' } in package.json. The emitted file 'icon.svg' is empty
SVG file may not be found or path is incorrect.
fixVerify the SVG path is correct and the file exists. Use absolute paths if needed.
Uncaught DOMException: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
Not calling the SVG import as a function (default mode).
fixCall icon() to get the DOM node, or set `stringify: true` to get a string.
Audit
Dependencies
rollupoptionalpeer dependency: must be installed with Rollup ^3.0.0 or ^4.0.0