react-native-svg: "TypeError": "Network request failed"

I got this error when importing local svg file using svgUri <SvgUri width=“100%” height=“100%” uri={require(‘…/…/assets/icons/logo.svg’)} />`

`

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 10
  • Comments: 20 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I’m getting “Network request failed” when I attempt to load a svg using a data uri on android. This works on iOS.

<SvgCssUri
    height={100}
    width={100}
    uri={
"data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20100%20100%22%3E%3Cpath%20fill%3D%22%2354b847%22%20d%3D%22M0%200h100v100H0z%22%2F%3E%3Cpath%20fill%3D%22%23fff%22%20d%3D%22M61.6%2069.1h-17V38.3h8.6v25.4h8.2c5.7%200%208.1-3.9%208.1-14.1S66.8%2036.4%2061%2036.4H42.2v32.7h-8.4V36.3H21.4v-5.4h42.3c10.2%200%2015%205.3%2015%2018.6-.1%2017.4-7.3%2019.6-17.1%2019.6%22%2F%3E%3C%2Fsvg%3E"
    }
/>

The solution I found is make the Svg a React component instead of an image file

Can you describe how to solve it, thanks

getting this on iOS

import {View, Image} from 'react-native';
import {SvgUri} from 'react-native-svg';

const {uri, width, height} = Image.resolveAssetSource(require('../../assets/example.svg'));

<SvgUri
  width={width}
  height={height}
  uri={uri}
/>

I’m currently having the same issue on iPhone 13, iOS 16.4: Console Error: Network request failed