react-native icon indicating copy to clipboard operation
react-native copied to clipboard

v0.14.2 Static Image Asset Unable to Be Required when run on iOS from Xcode

Open starfalling opened this issue 11 years ago • 3 comments

It shows the following error when press run of Xcode on Simulators: uncaught error Error: UnableToResolveError: Unable to resolve module image!ic_search from ****/js/tab.home.js: Invalid directory /Users/node_modules/image!ic_search

I entered deep into the code, and found why it doesn't work.

in file react-native/private-cli/src/util/Config.js, it tries to find rn-cli.config.js from parent directories from react-native/local-cli, but file rn-cli.config.js is under directory react-native/packager/, so it cannot find it, and function getAssetRoots() will just return an empty array as configured inside default.config.js

starfalling avatar Nov 14 '15 13:11 starfalling

Hey, since 0.14.2 dealing with image for iOS and android  is unified. You have to specify relative path to image.

harakhovich avatar Nov 14 '15 22:11 harakhovich

@Maxyss so how to do this?

I changed function getAssetRoots in react-native/local-cli/default.config.js as follows and it works now. But I know that this is not the right way.

getAssetRoots() {
  return this.getProjectRoots();
},

starfalling avatar Nov 15 '15 03:11 starfalling

Closing this as this is related to old assets system.

satya164 avatar Dec 24 '15 18:12 satya164