3

I am using next.js 11.1.0 , my images are not showing saying (image below). I tried upgrading to next.js 12 but the problem still persist. I also tried using img tag and it works fine, just next/image not working. It seems not to work on live site production. My images are stored locally. Anyone encountered this?

enter image description here

                    <Image
                     src="images/Uploads/Activities/StoryTelling/3_2022-05-07203A383A38.jpeg"
                      width={500}
                      height={500}
                    />
  • 1
    A snippet of your code would help understand your problem. Could you also clarify if you are trying to display a local or external image? – paulin-crtn May 07 '22 at 12:03
  • Also try opening the page using dev server and see if you get any hints in server or browser console. You might need additional configuration inside `next.config.js`. – Webber May 07 '22 at 12:11
  • 3
    do you have `images/sample.jpg` in your public folder? – Webber May 07 '22 at 12:12
  • It works fine on dev server. I only encounter this on live server . I am using ubuntu server – Mike Tabag Estonanto May 07 '22 at 12:12
  • You might wanna look into your configuration for static assets. In dev server they're always served locally but in a production build it might look for them on CDN or other. – Webber May 07 '22 at 12:15
  • Also, the comment about dev server was meant to make you find hints in console, not see if it works or not :) – Webber May 07 '22 at 12:16

5 Answers5

3

If everything works fine on local but not in production it might be an image loader issue. I invite you to take a look at the documentation as you may need a custom function to resolve URLs.

Image loader

Built-in loader

I had the same issue when deploying on GCP but everything worked on Vercel.

paulin-crtn
  • 325
  • 2
  • 9
2

You have to write src={/photoname.format} when it's Next Image, instead of the whole path.

ellamusen
  • 31
  • 4
  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 21 '22 at 11:42
  • This should be the correct answer. By default you don't have to explicitly mention `/public` directory in `src` props of `Image` component, instead you just add furthermore directory of your static file like `/images/rose.svg`, so `Next.js` will assume it to `/public/images/rose.svg` – Sabbir Sobhani May 26 '23 at 07:35
1

As Webber's second comment hints, the documentation states that all static files, like images, must be served from the public directory.

Another mention exists in this tutorial from Next.js.

While you are likely not still trying to figure this out, others could benefit from this clarity.

You can place your image in an images directory inside the public directory, and the path required would simply be /images/sample.jpg.

0

import img from './images/Uploads/Activities/StoryTelling/3_2022-05-07203A383A38.jpeg'

<Image
  src={img}
  width={500}
  height={500}
/>
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
0

Add these lines of code in the next.config.js file of your project folder

module.exports = nextConfig

module.exports = {
  images: {
    
    formats:['image/webp']
  },
}
juliomalves
  • 42,130
  • 20
  • 150
  • 146
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 08 '23 at 06:11