-
Notifications
You must be signed in to change notification settings - Fork 54
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
vite, react-ts --- Module '"*.svg"' has no exported member 'ReactComponent'. --- #44
Comments
If I understand it correctly, there is a section in the readme you can refer to:
and you don't need to declare it manually |
You can add this to your "types": ["vite-plugin-svgr/client"] If you are on VSCODE and it doesnt pick it up straight away, either restart vscode or ts server |
Added inside client.d.ts: But got this error: |
Put this to your
|
I'm having a similar issue, except I can compile but I'm getting this in my browser console log: Version: 2.4.0
I have: //vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import svgr from "vite-plugin-svgr";
export default defineConfig({
plugins: [react(), svgr()],
resolve: {
alias: {
src: "/src",
},
},
}); //vite-env.d.ts
/// <reference types="vite/client" />
/// <reference types="vite-plugin-svgr/client" /> // Component
import { ReactComponent as Icon} from '/src/assets/icon.svg'; I've also tried: //vite-env.d.ts
"types": [
"vite/client",
"vite-plugin-svgr/client"
], |
Hey guys, I figured it out. I bet all you guys struggled of this issue had set The type definition of this library is export a variable called "ReactComponent" when you import a svg file, not default export.
so Don't set the use this plugin like this:
|
@panjiangyi So what's the point of |
@lucsky IMO it gives you a choice, or compromise. If you think having to type |
That being said, as an OSS, I think the best course of action here is for a community hero to provide the typing for when
|
Does anyone have a way to get the /// <reference types="vite/client" />
/// <reference types="vite-plugin-svgr/client" /> And my svg imports are still typed as |
Add the following to your tsconfig:
|
Have tried all suggested answers here and in documentation to no avail.. |
Tried everything from here and from stackoverflow. Nothing works. I always end up with Also tried doing what OP did, but no luck. Also added currently vite.config.ts has this I am really clueless after one day to trial and error. |
For the latest v4, please check out the document here: https://github.com/pd4d10/vite-plugin-svgr?tab=readme-ov-file#usage Background here: #71 (comment) |
If using v4 of this package, you need to change your imports from
to
|
i hope this helps someone, i resolved this issue by moving |
It looks like this syntax is not supported with Jest :( |
You need to add plugins: [
react(),
svgr({
svgrOptions: { exportType: 'named', ref: true },
include: '**/*.svg',
}),
], |
Hello i just installed this module in a vite/react-ts project, i'm getting this error when i'm importing an SVG
import { ReactComponent as HomeIcon } from "images/icons/IconSvg/home.svg"
The import works and the icon is shown.
I managed to get rid of the error by declaring this module
It doesn't really bother me, but i was wondering if there is a " cleaner " solution
Thanks for your responses :)
The text was updated successfully, but these errors were encountered: