Skip to content

Loading a local image using require() doesn't work #16909

@packouray

Description

@packouray

Hi,

Is this a bug report?

yes.

Actual Behavior

I'm getting "require() must have a single string literal argument" when I'm trying to require a local image.
Here is what I do :

I'm retrieving the image path as a string from Firebase database and I'm setting a state with it :

profilePicture: user.val().picture_1

here is the path => "../../img/user/profile/blank_profile.png"

Then I'm trying to set my image source using the path that I just retieved :

<Thumbnail large source={require(this.state.profilePicture)}/>

But I'm getting the error "require() must have a single string literal argument".

Thank you in advance !

Expected Behavior

The image is displayed.

Steps to Reproduce

Require a local url from firebase stored in a state.

Environment

Environment:
OS: Windows 10
Node: 6.10.2
Yarn: Not Found
npm: 3.10.10
Watchman: Not Found
Xcode: N/A
Android Studio: Version 2.3.0.0 AI-162.3871768

Packages: (wanted => installed)
react: 16.0.0-beta.5 => 16.0.0-beta.5
react-native: ^0.49.5 => 0.49.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ran CommandsOne of our bots successfully processed a command.Resolution: For Stack OverflowA question for Stack Overflow. Applying this label will cause issue to be closed.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