You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot load local images in 0.63.4 in iOS simulator #30670
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
@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"]) {
^
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?
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?
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
Activity
safaiyeh commentedon Jan 9, 2021
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
plnii commentedon Jan 9, 2021
@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'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/app/node_modules/react-native/Libraries/Image/RCTImageLoader.mm:629:12: error: use of undeclared identifier '_turboModuleRegistry'
&& ![_turboModuleRegistry moduleForName:"RCTNetworking"]) {
^
plnii commentedon Jan 9, 2021
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?
mechazod commentedon Jan 25, 2021
@plnii Did you try
importinstead ofrequire? BTW, what is the use case why did you userequire?plnii commentedon Jan 25, 2021
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?mechazod commentedon Jan 25, 2021
@plnii I see, you can try this file structure.
Let say I'm inside
App.js, then I want to load those two or more imagesAccess local files via import
<Image source={Image1} />Access local files via require
<Image source={require('./images/test2.png')} />plnii commentedon Jan 27, 2021
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