1

I searched and found that I was supposed to use require() but it doesn't seem to be working.

<img src={require("../assets/img/business.png")} alt="business" />

I can confirm that this image path is correct, but on the inspect mode it says the src of my image is [object Module].

Also, when I import the image from the same path, it works completely fine.

Could this be because I am using typescript? I also saw people talking about browserify on another post, does browserify have anything to do with me being unable to use require?

Jiayi Shen
  • 11
  • 3

2 Answers2

6

Can u try using .default ?

<img src={require("../assets/img/business.png").default} />
Sudhir
  • 126
  • 1
  • 6
  • This solved an issue I had with dynamic `require()` in a react component (https://stackoverflow.com/questions/68821228/display-images-with-a-loop-in-a-react-component). – Lou Aug 18 '21 at 09:50
0

I believe you might need some sort of a loader for to tell your code how to process the image.

Have a look at these following libraries

Muthusamy
  • 56
  • 9