Can't import svgs
See original GitHub issueIf I want to import my svg like import Star from '../../assets/svgs/pinnedStar.svg';
I get this error
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: number.
my rn-cli.config.js:
const { getDefaultConfig, mergeConfig } = require('metro-config');
module.exports = mergeConfig(
async () => {
const {
resolver: { sourceExts, assetExts },
} = await getDefaultConfig();
console.log(sourceExts);
return {
transformer: {
babelTransformerPath: require.resolve('react-native-svg-transformer'),
},
resolver: {
assetExts: assetExts.filter(ext => ext !== 'svg'),
sourceExts: [...sourceExts, 'svg'],
},
};
},
{
transformer: {
babelTransformerPath: require.resolve(
'react-native-typescript-transformer'
),
},
}
);
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:27 (16 by maintainers)
Top Results From Across the Web
Unable to import svg files in typescript - Stack Overflow
If you use webpack, you can do this by creating a custom types file. Create a file named custom.d.ts with the following content:...
Read more >Bug: [5.0] SVGs cannot be imported (not as components, but ...
Describe the bug When importing a SVG in a regular manner (not as a component): import Logo from './logo.svg' There is an error...
Read more >What if You Can't Import a File? | SVGator Help
What if you can't import a file · 1. If it's not a static SVG file · 2. If the code includes unrecognizable...
Read more >Importing svg not working properly - Ask the community
Note that if that SVGs are exported from Illustrator, masks in them won't import to Figma correctly. Also defs and use are not...
Read more >How to Import SVGs in a React and Vite app - freeCodeCamp
In this article, I will share with you the different ways of importing SVGs in React, as well as how the process works...
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
@kristerkari svg image is opening on devices but not on web getting following error,
DOMException: Failed to execute ‘createElement’ on ‘Document’: The tag name provided (‘/static/media/events-qengage.89418f90.svg’) is not a valid name.
@danbockapps and for typescript you might need to do
declare module "*.svg";
, I’m not sure, but you can try that.