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 (svgLoader)
✓ import svgLoader from 'vite-plugin-svg-loader'
✗ const svgLoader = require('vite-plugin-svg-loader')
ESM-only; CommonJS require will fail.
SVG file (default import)
✓ import svgData from './icon.svg'
✗ import svgData from 'vite-plugin-svg-loader!./icon.svg'
Default import returns a parsed JSON object. The ! syntax is for webpack, not Vite.
SVG file (?raw)
✓ import rawSvg from './icon.svg?raw'
✗ import rawSvg from './icon.svg?row'
The query parameter is ?raw (not ?row, despite README typo). From version 1.0.0, use ?raw.
SVG file (?url)
✓ import svgUrl from './icon.svg?url'
✗ import svgUrl from './icon.svg?file'
Returns the URL of the SVG file (default Vite asset behavior).
Shows basic setup in vite.config.ts and three import variants: default parsed object, raw string, and URL.
// vite.config.ts
import { defineConfig } from 'vite'
import svgLoader from 'vite-plugin-svg-loader'
export default defineConfig({
plugins: [svgLoader()]
})
// component.ts
import icon from './icon.svg'
console.log(icon)
// { tag: 'svg', attrs: { viewBox: '...' }, children: [...] }
import raw from './icon.svg?raw'
console.log(raw)
// <svg ...>...</svg>
import url from './icon.svg?url'
console.log(url)
// /assets/icon.abc123.svg
Errors
Common errors & fixes
Module '"vite-plugin-svg-loader"' has no exported member 'default'. Did you mean to use 'import svgLoader from "vite-plugin-svg-loader"' instead?
Using TypeScript with allowSyntheticDefaultImports: false or importing as { svgLoader }.
fixUse import svgLoader from 'vite-plugin-svg-loader' (default import).
Unknown plugin: 'vite-plugin-svg-loader'
Plugin not found because it's not installed or path is incorrect.
fixInstall the plugin: npm install --save-dev vite-plugin-svg-loader
Invalid query parameter '?row'. Only ?raw and ?url are supported.
Using the typo ?row from the README.
Audit
Dependencies
viterequiredPeer dependency: the plugin requires Vite >=2.0.0-0 to function as a Vite plugin.