question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rollup svgr + url plugin not exporting ReactComponent

See original GitHub issue

In 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:13

github_iconTop GitHub Comments

12reactions
davidgarsancommented, Jun 15, 2021

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/rollup

Any updates?

5reactions
rmjwilburcommented, Jul 15, 2022

The following worked for me in rollup.config.js:

svgr({ exportType: 'named', jsxRuntime: 'automatic' }),
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found