Registry /
web-framework / gatsby-plugin-svgr-loader
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–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
plugin in gatsby-config
✓ {
resolve: 'gatsby-plugin-svgr-loader',
options: { rule: { include: /assets/ } }
}
✗ {
resolve: "gatsby-plugin-svgr-loader",
options: { include: /assets/ }
}
Options must be wrapped in a `rule` object; `include` cannot be at top level.
React component from SVG
✓ import Icon from './assets/icon.svg';
✗ const Icon = require('./assets/icon.svg');
Default import works with SVGR; require may not work in all Gatsby setups.
Inline SVG pattern
✓ import Something from './path/something.inline.svg';
✗ import Something from './path/something.svg';
Use `.inline.svg` naming convention and corresponding include regex to avoid url-loader conflicts.
Configures the plugin to treat .inline.svg files as React components via SVGR, while other SVGs remain handled by url-loader.
// Install
npm install gatsby-plugin-svgr-loader
// gatsby-config.js
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-svgr-loader',
options: {
rule: {
include: /\.inline\.svg$/
}
}
}
]
}
// In a React component
import React from 'react';
import InlineIcon from './assets/icon.inline.svg';
const App = () => <InlineIcon />;
export default App;
Errors
Common errors & fixes
Error: Cannot find module '@svgr/webpack'
@svgr/webpack not installed; it's a peer dependency not auto-installed.
fixRun: npm install @svgr/webpack
Error: [gatsby-plugin-svgr-loader] `rule` option must be an object with `include` or `exclude`.
Options passed incorrectly, e.g., `include` at top level instead of inside `rule`.
fixUse: options: { rule: { include: /regex/ } } (Webpack) Module parse failed: Unexpected token on SVG file
SVG file is being processed by multiple loaders; plugin didn't exclude it from url-loader properly.
fixEnsure `rule.include` or `rule.exclude` is set correctly to avoid conflicts.
Audit
Dependencies
@svgr/webpackrequiredrequired for SVG transformation