I want to use 'react-svg-loader' webpack loader with next.js to load .svg files.
For now I got errors like:
Steps to reproduce the behavior, please provide code snippets or a repository:
config.module.rules.push({
test: /\.svg$/,
use: [
{
loader: 'babel-loader',
},
{
loader: 'react-svg-loader',
options: {
jsx: true,
svgo: {
plugins: [
{
cleanupIDs: {
prefix: {
toString() {
this.counter = this.counter || 0;
return `id-${this.counter++}`;
},
},
},
},
{
removeTitle: true,
},
],
},
},
},
],
});
import * as React from 'react';
import TestIcon from './icon/assets/age.svg';
export default () => <TestIcon/>;
I should see the rendered icon.
Just use public folder and just load it as a static img
From my prior experience, you might be applying two rules to the same SVG somewhere. Try console-logging config.module.rules
– is there one mentioning .svg
already? It could come from some Next.js plugin that you use.
The solution would be to narrow down the scope of the loader that you are adding, e.g:
config.module.rules.push({
test: /\.svg$/,
include: [require("path").resolve(__dirname, "src/my/specific/folder")],
use: /* ... */,
})
This is unlily to be the issue with Next.js itself.
@kachkaev yes, this was the issue. I've solved it. Thank you!
Just use public folder and just load it as a static img
people often want to import as a react component so they can reactively set properties, such as fill colour.
and saying "just don't" isn't helpful.
Most helpful comment
people often want to import as a react component so they can reactively set properties, such as fill colour.
and saying "just don't" isn't helpful.