Rollup svgr + url plugin not exporting ReactComponent
See original GitHub issueIn the docs there’s an example of the rollup url plugin + @svgr/rollup
, but I can’t seem to get it working properly. I put together a gist to demonstrate the issue. I’ll summarize below:
- SVGR version - 5.4.0
- Rollup Version: 2.23.1
Rollup Config:
import svgr from '@svgr/rollup';
import url from '@rollup/plugin-url';
export default {
input: './src/index.js',
output: {
file: './build/index.js',
format: 'esm'
},
external: ['react'],
plugins: [
url(),
svgr(),
]
}
Index:
import air_play from './icons/airplay.svg';
export { air_play };
When I build I’m seeing this:
import 'react';
var airplay = "data:image/svg+xml,%3Csvg%20%20xmlns%3D%22..."; // clipped text
export { airplay as air_play };
Based on the docs I’d expect to see something like:
import { createEement } from 'react';
function SvgAirPlay() { ... } // generated from svgr
var airplay = "data:image/svg+xml,%3Csvg%20%20xmlns%3D%22..."; // clipped text
export default airplay;
export { SvgAirPlay as ReactComponent };
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:13
Top Results From Across the Web
Rollup.js - SVGR
SVGR provides an official rollup.js plugin to import SVG as React components. ... export the React Component via default export if there is...
Read more >@svgr/rollup - npm
Start using @svgr/rollup in your project by running `npm i @svgr/rollup`. ... React Component via default export if there is no other plugin...
Read more >svgr/rollup - npm.io
Using with url plugin ... It is possible to use it with url . ... The named export defaults to ReactComponent , but...
Read more >Unable to import SVG with Vite as ReactComponent
Add the plugin SVGR to vite in vite.config.js ... import react from '@vitejs/plugin-react'; import svgr from '@svgr/rollup'; export default ...
Read more >How to use SVGs in React | Sanity.io guide
This article will explore how to use SVG in React in three examples. ... Writing React component template is not straightforward.
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
Getting the same error here from rollup build @atomicpages :
[!] Error: 'ReactComponent' is not exported by src/assets/images/plus.svg, imported by src/assets/images/icons.ts
Same stack, latest versions, as @o-mega: @rollup/plugin-typescript + @svgr/rollupAny updates?
The following worked for me in rollup.config.js: