Comments (5)
Same problem here.
from gatsby-plugin-react-svg.
Apparently if your config match something that isn't SVG you get that error, maybe on svg
folder has a file that isn't a SVG file. Thats an opinion based on experience, I don't delve in the code.
from gatsby-plugin-react-svg.
It is because .svg
files are still being consumed by the url-loader
plugin. Here is why:
The problem is in this conditional configuration:
const newUrlLoaderRule = (include || exclude) ? {
...imgsRule,
include: exclude,
exclude: include
} : {
...imgsRule,
test: new RegExp(imgsRule.test.toString().replace('svg|', '').slice(1, -1))
}
If you explicitly specify include: /images\/svgs/
, the final url loader configuration will be:
{
use: [
{
loader: '/.../node_modules/url-loader/dist/cjs.js',
options: [Object]
}
],
test: /\.(ico|svg|jpg|jpeg|png|gif|webp|avif)(\?.*)?$/,
include: undefined,
exclude: /images\/svgs/
}
If you leave options empty, like this:
plugins: [
{
resolve: "gatsby-plugin-react-svg",
options: {},
},
it will be:
{
use: [
{
loader: '/.../node_modules/url-loader/dist/cjs.js',
options: [Object]
}
],
test: /\.(ico|jpg|jpeg|png|gif|webp|avif)(\?.*)?$/
}
Here the test
entry is modified and skips svg
from being consumed by the url-loader
.
So it seems that having |svg|
in the test
both with exclude/include
regexes is not working as expected - url-loader
is still processing those images before svg-loader
. That is probably a bug.
from gatsby-plugin-react-svg.
Honestly, I don't use gatsby anymore these days, and I haven't used this library myself since before the 3.0 release, but specifying include
works fine for me in ^2.0 in older gatsby projects and the logic still seems correct to me; when specifying include
, those paths will be exclude
d by url-loader
, so I still don't see what the issue is despite your examples above.
Pull requests welcome, surely.
Edit: I updated an older project to use gatsby 3 and the most recent version of this plugin, and specifying include
still indeed works.
gatsby-config.js
:
{
resolve: 'gatsby-plugin-react-svg',
options: {
rule: {
include: /icons/
}
}
},
index.js
:
...
import TeamIcon from '../images/icons/team.svg';
export default function IndexPage({ data }) {
return (
<Layout
title={data.site.siteMetadata.title}
className="home"
>
<TeamIcon />
</Layout>
);
}
SVG icon is rendered correctly.
Same include but with this config results in an error:
{
resolve: 'gatsby-plugin-react-svg',
options: {
rule: {
include: /icfons/
}
}
},
So I'm not sure what's going on causing it to not work for you.
from gatsby-plugin-react-svg.
I have the same issue.
from gatsby-plugin-react-svg.
Related Issues (20)
- Dynamic imports HOT 2
- This plugin works fine in development mode - but on prod it behaves different.
- Invalid Character found in every SVG I have HOT 1
- is it possible to use svg on filepath url
- Module parse failed: Unexpected character '' HOT 3
- Error query.substr is not a function
- unable to use list-style with imported SVG HOT 2
- query parameter `classIdPrefix: true` not working HOT 5
- Multiple same svg only render single svg HOT 4
- Default plugin setup not working in Gatsby version 3: "maskType" HOT 3
- Unable to resolve svg path in deploy(Netlify) but works in localhost HOT 1
- Typescript Error HOT 5
- Error on documentation in gatsby-config.js
- receiving Error: Invalid character entity when importing an svg file as Component
- Mocking Component in Jest HOT 1
- Error building on Vercel HOT 3
- Add support for Gatsby V5 HOT 3
- Dependency `svg-react-loader` uses vulnerable version of `loader-utils` HOT 2
- SVG Image Import: Support for defaultProps will be removed from function components HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gatsby-plugin-react-svg.