Skip to content

Cannot load local images in 0.63.4 in iOS simulator #30670

Closed

Description

@plnii

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

After adding image to source tree, when using code like <Image source={ require('./path_to_image.png') } /> the image is not rendered and no error is shown. If I use a URI or icon, it renders.

React Native version:

Run react-native info in your terminal and copy the results here.
System:
OS: macOS 11.1
CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
Memory: 500.91 MB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.5.0 - /usr/local/bin/node
Yarn: 1.22.5 - ~.yarn/bin/yarn
npm: 6.14.9 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.0 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.3, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
Android SDK: Not Found
IDEs:
Android Studio: 4.1 AI-201.8743.12.41.6953283
Xcode: 12.3/12C33 - /usr/bin/xcodebuild
Languages:
Java: Not Found
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.4 => 0.63.4
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps To Reproduce

See above.

Expected Results

Image renders

Activity

  1. safaiyeh commented on Jan 9, 2021

    @safaiyeh
    Contributor

    Hi @plnii thank you for the issue. Could you test this PR and see if it helps your case? #29595

    You could use patch-package to test it out. https://github.com/ds300/patch-package

  2. added
    DXIssues concerning how the developer experience can be improved.
    on Jan 9, 2021
  3. plnii commented on Jan 9, 2021

    @plnii
    Author

    @safaiyeh I'm not sure exactly how to apply this patch. But I edited the RCTImageLoader.mm file. Then used Patch-Package to build and apply the fix. Using React Native 0.63.4. Here's part of the build errors:

    `/app/node_modules/react-native/Libraries/Image/RCTImageLoader.mm:102:13: error: property implementation must have its declaration in interface 'RCTImageLoader' or one of its extensions
    @synthesize turboModuleRegistry = _turboModuleRegistry;
    ^
    /app/node_modules/react-native/Libraries/Image/RCTImageLoader.mm:1145:106: error: no type named 'InitParams' in 'facebook::react::ObjCTurboModule'

    • (std::shared_ptrfacebook::react::TurboModule)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
      /app/node_modules/react-native/Libraries/Image/RCTImageLoader.mm:629:12: error: use of undeclared identifier '_turboModuleRegistry'
      && ![_turboModuleRegistry moduleForName:"RCTNetworking"]) {
      ^
  4. plnii commented on Jan 9, 2021

    @plnii
    Author

    This seems to indicate that more than one file needs to be changed but the PR only has one file. I'm not sure how to track down the dependencies or get them into my project without a lot of work on my end. Could I pull the latest release candidate via yarn and patch that? Or maybe a nightly build?

  5. mechazod commented on Jan 25, 2021

    @mechazod

    @plnii Did you try import instead of require? BTW, what is the use case why did you use require?

  6. plnii commented on Jan 25, 2021

    @plnii
    Author

    I'm just trying to load a bunch of local images as per https://reactnative.dev/docs/images

    It's been a few weeks, but I tried every way I could find to get images to load and had no success with local images. Temporarily I'm loading from an external URI, which is not ideal. I'm not sure specifically what you mean by import. Do you think a particular way of importing will work?

  7. mechazod commented on Jan 25, 2021

    @mechazod

    @plnii I see, you can try this file structure.

    .
    |--src
    |---App.js
    |---images
    |----test1.jpg
    |----test2.png
    |----...
    index.js
    

    Let say I'm inside App.js, then I want to load those two or more images

    Access local files via import
    import Image1 from './images/test1.jpg';
    

    <Image source={Image1} />

    Access local files via require

    <Image source={require('./images/test2.png')} />

  8. plnii commented on Jan 27, 2021

    @plnii
    Author

    I tested the above approach it seems to have worked. It turned out the defect I was experiencing was with React Native Elements, which use the same Image tag. I see they fixed the defect here: react-native-elements/react-native-elements#2717

  9. locked as resolved and limited conversation to collaborators on Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: ImageDXIssues concerning how the developer experience can be improved.Platform: iOSiOS applications.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions