Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with string interpolation if the images folder isn't in the current directory #131

Open
arimendelow opened this issue Feb 18, 2020 · 2 comments

Comments

@arimendelow
Copy link

If you've got images that are used by several different components, it's a good idea to have them only once in your project and then just require them wherever needed, like this:

require("../../images/image.jpg")
require("./images/image.jpg")

with these both referencing the same file. This works, as expected.

Similarly, if you're displaying an array of objects, it's nice to be able to do this:

objects = [
   {image: "./images/photo.jpg"},
   etc...
]

objects.map((object) => {
   <img
      src=require{`${object.image}`}
   />
}

This also works perfectly.

What doesn't work is attempting to combine the two:

objects = [
   {image: "../../images/photo.jpg"},
   etc...
]

objects.map((object) => {
   <img
      src=require{`${object.image}`}
   />
}

This throws an error stating that it Cannot find module '../../images/image.jpg'.

Why is this?

@chaddjohnson
Copy link

Using a partially dynamic path as suggested here is what worked for me.

@albertpeiro
Copy link

Found a similar issue with size param:
#156

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants