twopluszero / next-images

Import images in Next.js (supports jpg, jpeg, svg, png and gif images)
MIT License
948 stars 67 forks source link

It does not work #59

Closed vincentpham13 closed 3 years ago

vincentpham13 commented 3 years ago

Which folder did you mean to put the images? I created an images folder inside the public folder but still got the error. As your guide, the image should be located in the same directory of the code file, that's so weird.

arefaslani commented 3 years ago

Hey @vincentpham13. Sorry for the late response. The image could be anywhere, but I prefer to put it alongside the component file. As you see in this example:

export default () => <div>
  <img src={require('./my-image.jpg')} />
</div>

the relative path is showing that the image is alongside the component itself. So to make it more clear, suppose that the component in the previous example is in this path: /components/MyAwesomeComponent/index.js, then the image file is here /components/MyAwesomeComponent/my-image.jpg.