vite-plugin-svgr: Plugins don't work
40/5000 I’m having a problem. Your plug-in doesn’t work after using it. I don’t know what’s wrong with the configuration. The browser returned the following error:
Uncaught DOMException: Failed to execute ‘createElement’ on ‘Document’: The tag name provided (‘/src/images/smcLogo.svg’) is not a valid name.
my code is this:
import React, { Component } from 'react';
import cssObj from './Logo.css';
import Icon from '@ant-design/icons';
import {ReactComponent as SMCLogo } from '@/images/smcLogo.svg';
class Logo extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div style={{width: this.props.width, height: this.props.height, paddingTop:'10px' }} >
<div className={cssObj.LogoLeft}>
<Icon component={()=><SMCLogo width="70px" height="22px" fill="#B7C1CF"/>} />
</div>
</div>
);
}
}
export default Logo;
Looking forward to your reply. thank you
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 8
- Comments: 17 (1 by maintainers)
I’m having an issue here too where my svg files are not optimized by svgo at all. Here’s the config
using svgr in electron and vite, same problem, warning like:
Including svg like
Including svgr in vite config
A minimal repo is here:
https://github.com/zzswang/for-svgr-issue
Any ideas? Thanks
I had the same problem as I didn’t notice latest breaking change of V4
If you use the latest version vite-plugin-svgr (v4), you have to update the import syntax as follows
I figured out and it seems working as a pie. here is full config which will make things better for newcomers
@alkanna I meet same issue, I fix my issue by by add
@svgr/plugin-svgo
and@svgr/plugin-jsx
, see https://github.com/pd4d10/vite-plugin-svgr/issues/49 for more detailsSorry thought it was obvious.
jsxRuntimeExports.jsx("svgGithub", {}) }),
React.createElement("svgFacebook", null)
The element isn’t actually created, its null/empty.
I suggest everyone having trouble to just fire up a debugger to see what is going on. This makes it quite clear without waiting for anyone else to figure it out (which is not likely to happen).
Just
debugger
statements