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

'Requring invalid module "image!my-icon"' error when trying to include static image

Open clauderic opened this issue 11 years ago • 48 comments

When I try to require static assets as per http://facebook.github.io/react-native/docs/image.html#static-assets, I get the following error:

"Requring invalid module "image!my-icon". If you are sure the module is there, try restarting the packager."

Not sure if there are any steps I'm missing? I've included the asset in my Images.xcassets library

clauderic avatar Mar 26 '15 23:03 clauderic

I don't know what is causing this issue, but ide in the irc told me to manually run:

$ node_modules/react-native/packager/packager.sh --assetRoots path/to/Images.xcassets

And that seems to work.

jimmyhmiller avatar Mar 27 '15 00:03 jimmyhmiller

That didn't seem to do the trick unfortunately. Any other ideas of things I might have missed?

clauderic avatar Mar 27 '15 00:03 clauderic

The above fix worked, thanks!

clauderic avatar Mar 27 '15 00:03 clauderic

published v0.2.1

amasad avatar Mar 27 '15 00:03 amasad

Where should I put the static assets then? in iOS/Images.xcassets?

lazywei avatar Mar 27 '15 06:03 lazywei

@amasad it seems like the fix in #286 was later reverted by 31c4ff0? but fwiw I applied that diff manually to my packager and still couldn't get images to work. Inspecting the ReactPackager middleware to see if I can debug this further.

pedro avatar Mar 27 '15 23:03 pedro

@pedro uggh that's clowny, I'll get it back shortly

amasad avatar Mar 28 '15 02:03 amasad

brought this back in v0.3.1

amasad avatar Mar 28 '15 05:03 amasad

That patch worked for me. @pedro did you do npm install react-native -g instead of npm install react-native -s by any chance?

@amasad It's a bit fragile, because node_modules can be pretty much anywhere relative to the xcode project.

syrnick avatar Mar 29 '15 16:03 syrnick

@amasad has this bug definitely been closed ?

it originally didn't work, then worked for 2 days and now i've tried importing different images, on 3 different projects, and none work, even in the examples projects...

tried both launching default packager.sh and the command line where you specify assetRoots

always RED SCREEN: requiring unknown module...

JonathanMatthey avatar Mar 31 '15 01:03 JonathanMatthey

Odd, still having issues here too. I have the react-native package installed locally with my app (under node_modules in the root folder).

pedro avatar Mar 31 '15 01:03 pedro

ah, doh, was just using it wrong.

Not familiar with Images.xcassets, thought I needed to refer to images by the name of the group I defined in Xcode. But debugging the react-native packager I saw it still adds assets by the original image name, so using these instead works.

pedro avatar Mar 31 '15 03:03 pedro

It should work now. But I know it's painful, working on making it a lot nicer.

amasad avatar Apr 01 '15 02:04 amasad

Hi, Now I seem to be facing the same issue, referring to the images by the image name does not work. E.g. I have Avatar.png, [email protected], [email protected] in my Images.xcassets, and I use require('image!Avatar') does not work. Any clues?

I also used this to launch, also does not work... $ node_modules/react-native/packager/packager.sh --assetRoots path/to/Images.xcassets

dickyj avatar Apr 19 '15 07:04 dickyj

I am also facing this problem, can't seem to get it to work, any ideas?

josebalius avatar Apr 20 '15 20:04 josebalius

What are the errors you're seeing?

amasad avatar Apr 20 '15 21:04 amasad

@amasad I am getting the error at the title of the thread. I did a bit more reading and named the image set the same as the file name of the image, and that seems to have fixed it.

josebalius avatar Apr 20 '15 21:04 josebalius

Face the same problem....

SatanWoo avatar Apr 25 '15 17:04 SatanWoo

@SatanWoo make sure you use the same name of the original filename as the name of your image set. That seemed to work for me.

josebalius avatar Apr 25 '15 17:04 josebalius

same.. its not working. When you talk about node_modules/react-native/packager/packager.sh --assetRoots path/to/Images.xcassets

where should u run it from ?

fkilaiwi avatar Apr 25 '15 23:04 fkilaiwi