react-native-svg-transformer: Invariant Violation: Element type is invalid
I’m getting the following error when importing SVG’s:
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: number.
Check the render method of `MySVG`.
My metro config: (the one from the example app does not work for me)
const { getDefaultConfig, mergeConfig } = require("metro-config");
const svgConfig = (async () => {
const {
resolver: { sourceExts, assetExts }
} = await getDefaultConfig();
return {
transformer: {
babelTransformerPath: require.resolve("react-native-svg-transformer")
},
resolver: {
assetExts: assetExts.filter(ext => ext !== "svg"),
sourceExts: [...sourceExts, "svg"]
}
};
})();
const defaultConfig = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
};
module.exports = mergeConfig(svgConfig, defaultConfig);
I can get the example app to work fine. I tried to alter a few things there, to see if I could break it. No clues yet. I suspect this is a config issue.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 18 (2 by maintainers)
i had the same issue, after i checked the metro.config.js, i found out that i was wrong
old : `
`
New : `
`
Heey, the example is working for me but for my application SVG is not working, following configs from my app
metro config
Cant import SVG My metro.config.js is
My Svg file is stored in rootdir/images/cal_burning_icon.svg Contents:
My very simple component is:
error i am getting. i verified that react-native-svg-transformer & react-native-svg are properly installed, but still i am getting this error
anyone know how to fix. tried above answers. didn’t fix my issue
Does not work for me.
after I restart the project, it works. So everyone, after you edit the file, restart the whole project.
@parmarkamlesh I just tested your example with a fresh React Native install, and it’s working just fine. I have a feeling that you might have forgotten to restart the packager after making your changes.
@Simek @julioxavierr I would suggest not to use the
mergeConfigfunction if it is not needed. So I guess that you could use just a single config instead.