importing .svg does not work on the web, Warning: </static/media/splashScreen.0f923900.svg /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.
See original GitHub issueI have installed in my project expo install react-native-svg
.
I have exported the svg as a component by doing:
import Logo from './logo.svg';
export default Logo;
It can render on native but fail on the web.
bundle.js:69367 Warning: </static/media/splashScreen.0f923900.svg /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.
I have followed that configuration https://github.com/react-native-community/react-native-svg#use-with-svg-files
My metro.config.js
is equal:
const { getDefaultConfig } = require('metro-config');
module.exports = (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'],
},
};
})();
My app.json
got added
{
+ "packagerOpts": {
+ "config": "metro.config.js",
+ "sourceExts": ["js", "jsx", "ts", "tsx", "svg"]
+ },
}
- react-native-svg 9.13.3
- react-native-svg-transformer 0.14.3
- SDK: 36 Documentation: https://docs.expo.io/versions/latest/sdk/svg/
Issue Analytics
- State:
- Created 4 years ago
- Comments:18 (1 by maintainers)
Top Results From Across the Web
import SVG as React Components with webpack 5
Use PascalCase for React components, or lowercase for HTML elements. and the SVG doesn't show. I can't import it as a React Component....
Read more >How to use SVGs in React | Sanity.io guide
There are a few ways to use an SVG in a React app: Use it as a regular image; Import it as a...
Read more >How to use SVG Icons as React Components - Robin Wieruch
A walkthrough on how to use SVG Icons in React applications. SVGR + Webpack are the perfect fit to make it happen...
Read more >How To Import SVGs into NextJS | Frontend Digest
Then we can import our SVG file as normal, and use it like any other React component. 2. Use babel-plugin-react-svg. If you prefer...
Read more >How to Import SVGs in a React and Vite app - freeCodeCamp
Are you having difficulties importing SVGs into your React app? This is a problem that many developers face, especially when setting up a ......
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
For anyone going this path (like I did), make sure to use
src
instead ofhref
.I’m not using any .svg files in any expo web project at the moment. So I have no such example to show you as I haven’t even attempted to do what you’re doing. Expo has a default metro / webpack configuration, but it’s not my expertise, and completely unrelated to this library.
you can use: File.js File.web.js File.ios.js File.android.js File.windows.js File.native.js File.future.platform.js File.custom.test.e2e.js File.jest.js
and do this in e.g. ExtraFile.js:
and it’ll use the platform specific one depending on what you’ve made available and how you’ve configured metro / webpack / rollup / other web bundlers you’ve chosen to use.