react-native-svg-transformer: With Expo web: Failed to execute 'createElement' on 'Document'
Hello,
I am using Expo 39’s managed workflow.
I followed the installation instruction, created the metro.config.js file, and copy-pasted the content from the instructions. I also added the packagerOpts field to my app.json.
For testing purpose, I renamed my SVG file to logo.svg and used the following code in my app:
import Logo from "../../assets/images/avatars/logo.svg"
function TestComp() {
const size = 120;
return <Logo width={size} height={size}/>
}
Unfortunately, I am now getting the error:
InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided ('/static/media/logo.6a5b59b1.svg') is not a valid name.
Any idea about what is causing the error?
I don’t know if it is related, but I do have a babel.config.js file in my root folder.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 3
- Comments: 15 (2 by maintainers)
encountered the same issue,
i solve this by adding
babel-plugin-inline-react-svgas dev dependenciesthen add this to your
babel.config.jsthanks to this guy https://github.com/boopathi/react-svg-loader/issues/197#issuecomment-377562447
I created a temporary solution focused on the problem related to Expo, if you want you can take a look:
https://github.com/lucassouza16/react-native-svg-transformer-fix-expo
@divonelnc I just merged a PR to update the instructions for Expo, can you check the README again if that matches the config that you have in use?
I am getting the same issue with SDK 40 with an expo managed app:
Error
Steps taken
I have placed my SVGs under
./src/assets/.... An example import I’m doing is:Notably, if I use
babel-plugin-inline-react-svgas a plugin, it works like a charm on web: however it is not compatible with mobile.Config files
Yes, the author suggested a solution to me that solved the problem for me, you can remove the workaround and implement it:
https://github.com/kristerkari/react-native-svg-transformer/issues/135#issuecomment-1008310514
I saw that you removed the repository with the temp fix and just wondering if you’ve found a better, permanent solution for this, maybe?
SVG import in
create-react-appshould be like this:In native it should be like this:
The import syntax for
create-react-appis different from the syntax for native. @kristerkari any way we can fix this ?