question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not rendering local images

See original GitHub issue

Thank you for your time and energy for maintaining this open source project.

I expected easy local file support like react-native-svg-uri so I spent quite some time to search for similar issue in this repository but surprisingly couldn’t find any. Hence opening this issue.

Description of Bug & Unexpected behavior, and Steps To Reproduce

Mimicking the README example, I do

import * as React from 'react';
import { SvgUri } from 'react-native-svg';

export default () => (
  <SvgUri
    width="100%"
    height="100%"
    uri={require('../assets/example.svg')}
  />
);

Remote urls like the original uri="http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg" works perfectly, but is blank (not rendering anything) for local files.

This worked in react-native-svg-uri but in that thread you also stated that react-native-svg now supports this functionality. And considering that people are still defaulting to using react-native-svg-uri to this day it means that this buggy and unexpected behavior is losing customers as they are using the workaround. It is okay if the workaround is good, the problem is the workaround, react-native-svg-uri, is buggy and no longer active and since react-native-svg supports this functionality, I assume that you would want to look into this issue to help out everyone who initially tried to use this library but faced similar problems.

If you do not correct the default behavior, then similar issues would be opened again and again the issues always end with the workaround’s creator asking people to use the workaround, e.g. https://github.com/react-native-community/react-native-svg/issues/1204, https://github.com/react-native-community/react-native-svg/issues/310, https://github.com/react-native-community/react-native-svg/issues/612, https://github.com/react-native-community/react-native-svg/issues/510, https://github.com/react-native-community/react-native-svg/issues/347, https://github.com/react-native-community/react-native-svg/issues/310, https://github.com/expo/expo/issues/2402, which is not ideal and keeps causing confusions, as people will always ask you something about the workaround, which I am sure you are already fed up with.

Environment info

"react-native": "^0.61.5",
"react-native-svg": "9.13.3"

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:30

github_iconTop GitHub Comments

7reactions
vinayasenacommented, Sep 3, 2020

@diazevedo Hope you have already solved the issue, just for info the following is how i solved the issue on my end

import { WithLocalSvg} from ‘react-native-svg’; <WithLocalSvg width=“100%” height=“100%” asset={require(‘…/assets/images/createTag.svg’)} />

4reactions
holy1crabcommented, May 27, 2022

If anyone comes across the thread this is how I ultimately ended up solving this issue in the expo 42, react-native: 42. Be sure to take away react-native-svg-transformer if you have put any of that in your project.

import { Image } from 'react-native';
import { SvgUri } from 'react-native-svg';
const uri = Image.resolveAssetSource(require('image.svg'))
<SvgUri
    width={width}
    height={width}
    uri={uri}
  />

Maybe something has changed or just a misspell but Image.resolveAssetSource returns an object with uri property (https://reactnative.dev/docs/image#resolveassetsource). So, the actual code should be like this:

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}
/>

notice the object destructuring. And it actually works (without react-native-svg-transformer)! Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix image not showing in an HTML page
Every image in HTML is rendered by using the <img> tag with the image source specified in the src attribute. You can put...
Read more >
Image is not showing in browser? - html - Stack Overflow
The reason was: My image was named image.jpg and a page named about.html could not load it while login.html could. This was because...
Read more >
Why can I not see the images on my website? - Encode.Host
There are several possible reasons why your images are not showing up on your pages as expected: The image file is not located...
Read more >
HTML Image Not Showing - Position Is Everything
One of the reasons why your HTML image not showing in browser is that its file is not located in the same folder...
Read more >
7 Reasons Why Images Are Not Loading on Your Website
7 Reasons Why Images Are Not Loading on Your Website · 1. Incorrect File Paths · 2. Files Names Misspelled · 3. Wrong...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found