Importing SVG as react component does not work as mentioned in the docs.
See original GitHub issue🐛 bug report
I am trying to import SVG as react component based on the documentation from parcel site. Instead of the svg being rendered as a component in the page, the build actually fails. With an error - @parcel/core: No transformers found for src/assets/logo.jsx with pipeline: 'jsx'.
🎛 Configuration (.babelrc, package.json, cli command)
Using default babel configuration.
// package.json
{
"name": "parcel-react-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "parcel src/index.html"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@parcel/transformer-svg-react": "^2.2.1",
"parcel": "^2.2.1"
},
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
}
}
// .parcelrc
{
"extends": "@parcel/config-default",
"transformers": {
"jsx:*.svg": ["...", "@parcel/transformer-svg-react"]
}
}
🤔 Expected Behavior
The svg image should be loaded as a react component in the webpage.
😯 Current Behavior
An error is thrown saying @parcel/core: No transformers found for src/assets/logo.jsx with pipeline: 'jsx'.
💁 Possible Solution
🔦 Context
I am trying to import a svg image as a react component.
💻 Code Sample
Clone this repo and run yarn && yarn run dev
🌍 Your Environment
Software | Version(s) |
---|---|
Parcel | 2.2.0 |
Node | 16.13.2 |
npm/Yarn | 8.1.2 / 1.22.17 |
Operating System | Windows 10 |
Attachments:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:24
- Comments:8 (1 by maintainers)
Top Results From Across the Web
React SVG import as a Component does not render
Try: import { default as logo } from '../logo.svg';. and use as source in a node of type img, like this: <img src={logo}...
Read more >How to use SVGs in React | Sanity.io guide
There are a few ways to use an SVG in a React app: Use it as a regular image; Import it as a...
Read more >React SVG: How to use SVGs best in React - CopyCat Blog
In this article, we'll look at react SVG - importing SVG into react, how to convert SVG to components, and much more.
Read more >How to use SVGs in React - LogRocket Blog
Also, if you use inline SVG in your code, the browser does not have ... SVGs can be imported and used directly as...
Read more >react-native-svg - npm
Opening issues. Verify that it is still an issue with the latest version as specified in the previous step. If so, open a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@MLNW - I hit the same error that you did - I think it’s related to #7389
I found two workarounds: (1) remove inline style props on any svgs you are importing through your
jsx:*.svg
named pipeline or (2) remove the@transformer/svg
plugin from that pipeline (i.e. remove the"..."
entry, which includes this by default). The final config that worked for me was:No, its not resolved, this is a workaround not a fix.