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.

[RN 0.64] Image component is not able to find images marked as .android.png & .ios.png

See original GitHub issue

As per react-native documentation

The image name is resolved the same way JS modules are resolved. In the example above, the bundler will look for my-icon.png in the same folder as the component that requires it. Also, if you have my-icon.ios.png and my-icon.android.png, the bundler will pick the correct file for the platform.

Folder Structure

 assets
     add.android.png
     add@2x.android.png
     add@3x.android.png
     add.ios.png
     add@2x.ios.png
     add@3x.ios.png

Code:

<Image source={require(‘./add.png’)} />

Error:

Unable to resolve module add.png from AwesomeProject/App.js: add.png could not be found within the project or in these directories: node_modules

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

1reaction
tplortscommented, Jul 1, 2021

Update: https://github.com/facebook/react-native/issues/31348#issuecomment-867298139


@irodeanu I was having this problem too. I ended up finding (just by tinkering around) that requiring images with these platform-specific extensions works fine if I just provide a default file.

So in your case, since you have add.ios.png & add.android.png, try also picking one to version to be your default and copy it into add.png. I would be curious to know if that ends up working for you (and any others here that have experience this problem).

If this is now the intended requirement for platform-specific image files, then perhaps it would be helpful to add a note to https://reactnative.dev/docs/images Right now it just says

Also, if you have my-icon.ios.png and my-icon.android.png, the bundler will pick the correct file for the platform.

So something like “you must also provide a default image file my-icon.png”

0reactions
kaslcommented, Jun 24, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

expo - Image component in react native is not able to find ...
png and my-icon.android.png, the bundler will pick the correct file for the platform. But when I am trying to load images according to...
Read more >
Images - React Native
Images. Static Image Resources​. React Native provides a unified way of managing images and other media assets in your Android and iOS apps....
Read more >
Back up photos & videos - Android - Google Photos Help
You can automatically save your photos and videos to your Google Account with backup. ... from any device you're signed in to, but...
Read more >
react-native-image-picker - npm
Post-install Steps. iOS. Add the appropriate keys to your Info.plist,. If you are allowing user to select image/video from photos ...
Read more >
Displaying images with the React Native Image component
source will also accept a cache property that tells the component how to cache network images, but this only works for iOS. defaultSource....
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