Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No matching export in in svg file. #8

Closed
hannadrehman opened this issue Feb 7, 2022 · 6 comments
Closed

No matching export in in svg file. #8

hannadrehman opened this issue Feb 7, 2022 · 6 comments

Comments

@hannadrehman
Copy link

i am trying to import svg file like this

import { ReactComponent as ActivityIcon } from './pathToActivityIcon'

and it gives following error

 error: No matching export in "/pathToSvgFile.svg" for import "ReactComponent"
 import { ReactComponent } from '.pathToSvgFile.svg'

@kazijawad
Copy link
Owner

Hi, could you provide a code reference I could take a look at?

@hannadrehman
Copy link
Author

@kazijawad i am trying to use it like its implemented in create react app . its mentioned here in their docs

import { ReactComponent as Logo } from './logo.svg';

function App() {
  return (
    <div>
      {/* Logo is an actual React component */}
      <Logo />
    </div>
  );
}

@kazijawad
Copy link
Owner

Have you tried import Icon from './icon.svg';? If there is a repository I can look at that would be helpful.

@kazijawad
Copy link
Owner

Closing this issue because of inactivity.

@RIP21
Copy link

RIP21 commented Mar 25, 2022

@kazijawad default export works indeed. But most of the SVGR exports I saw generated by Webpack integration and Rollup integration generates a named export of ReactComponent
So import aDefault from './smth.svg' will give you a URL to a file to access or a base64 URL.
But import { ReactComponent } from './smth.svg' gives what your plugin gives now. So people that are looking for svgr plugin for esbuild look exactly for that UX and not the one you provide I think, maybe not by default, but at least some hint in the README :)
I want the same :)

@kazijawad
Copy link
Owner

@RIP21 Ah I see — yes this is currently possible with the SVGR API. It can be passed into the plugin options like this:

svgrPlugin({ exportType: 'named' })

It looks like the hosted SVGR documentation doesn't include all the possible options 😕
I tested it myself and was able to get import { ReactComponent } working. The named export can also be changed with the namedExport field. It might be useful to reference the SVGR source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants