Invariant Violation: Element type is invalid
See original GitHub issueI’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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:18 (2 by maintainers)
Top Results From Across the Web
Invariant Violation: Element type is invalid: expected a string ...
This error can rise if you try to import a non-existent component. Make sure you have no typo and that the component indeed...
Read more >Invariant Violation: Element type is invalid: expected ... - GitHub
Invariant Violation : Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Read more >(React) Element type is invalid, expected a string (for built in ...
To solve the error "Element type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got",...
Read more >Invariant Violation: Element type is invalid ... - YouTrack
Invariant Violation : Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Read more >Error Invariant Violation Element type is invalid expected a ...
Error Invariant Violation Element type is invalid expected a string for built-in components or a class function but got object.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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