Questions tagged [nextjs-image]

next/image is the built-in image component in NextJS 10. Please, do not use this tag for questions related to the next-images package (use [next-images] instead).

next/image is the Next.js team's solution to performant images on the web. The Next.js Image Component is just a drop-in replacement for the HTML <img> element, evolved for the modern web.

When using the next/image component, images are automatically lazy-loaded, meaning they're only rendered when the user is close to seeing the image. This prevents loading that 30% of images outside of the initial viewport.

The Automatic Image Optimization allows for resizing, optimizing, and serving images in modern formats like WebP when the browser supports it. This avoids shipping large images to devices with a smaller viewport. It also allows Next.js to automatically adopt future image formats and serve them to browsers that support those formats.

Automatic Image Optimization works with any image source. Even if the image is hosted by an external data source, like a CMS, it can still be optimized.

For usage and available props visit https://nextjs.org/docs/api-reference/next/image

310 questions
5
votes
2 answers

next/image configuration in Next.js config file

I’m implementing the Next.js Image component in my Headless project. The CMS that I’m using is WordPress. And since the image is coming from an external website, I need to specify the domain on next.config.js, as the documentation…
Grazielle Carvalho
  • 423
  • 1
  • 3
  • 11
5
votes
5 answers

Fetching an image from Firebase storage using next/image results in a 400 status code

I am using the NextJS Image component like this:
strangeQuirks
  • 4,761
  • 9
  • 40
  • 67
5
votes
2 answers

How to mock Next.js Image component in Storybook?

Next.js introduced a new Image component in v10 that's supposed to be a drop in replacement for the tag. I'm having an error when trying to view components that import next/image into Storybook: TypeError: imageData is undefined I have been…
drskullster
  • 781
  • 7
  • 20
4
votes
2 answers

NextJS ImageError: Unable to optimize image and unable to fallback to upstream image

I created middleware and add matcher /((?!api|_next/static|_next/image|favicon.ico|auth/login).*) in config middleware. When I try to run npm run dev.The result comes out like this: ImageError: Unable to optimize image and unable to fallback to…
rizk99z
  • 43
  • 8
4
votes
0 answers

Adding subfolders in public folder of next js

I am trying to create a website and it uses some files like a folder with images, I have saved these images folder in my public directory of project, it works fine on localhost, but when I try to deploy it with production setting, it cannot access…
4
votes
1 answer

Next.js - next dev does not reflect changes in code

Im running thru some tutorials and after about an hour of searching, I cant seem to find a solution for this. Any changes I make to a specific component (navbar) is not being reflected in the dev server. Im just trying to change and play around with…
RedFish
  • 41
  • 3
4
votes
2 answers

Next.js 11 - Image optimization is not working on production environment

I have a little issue with Image component in Next.js. I am using next 11.0.1 version, and I did not find any problems during development and local environment. The images are being optimized and everything is working fine. However, team and I find…
Samke11
  • 385
  • 5
  • 17
4
votes
1 answer

NEXT/Image Component URL issue

I am using NEXT/Image component and facing this issue: When I open the source code on chrome the image src is this: https://www.example.com/_next/image?url=%2Fimages%2Fhome%2FDog-image-1.jpg&w=384&q=100 but when I make google crawl the website in…
Adam Hill
  • 315
  • 3
  • 8
4
votes
4 answers

How can I present a different next/Image based on the user's preferred color scheme?

I'm trying to use a next/image instead of a regular img tag in the code below. With the regular tag, the following achieves exactly what I'm looking for:
Shawn
  • 10,931
  • 18
  • 81
  • 126
4
votes
2 answers

is it possible to use a svg as a placeholder for image in next js?

I'm using next Js Image tag (next/image). Is it possible to import a svg and use it as a placeholder until the image finish loading? I tried to create a use State and it to true on the "onLoad" of the tag as I would do in a img tag, but that doesn't…
Sku
  • 163
  • 2
  • 14
4
votes
1 answer

NextJS automatically replace tag to Component

I have the Problem, that I fetch HTML (and md) from a headless CMS (Directus). The Problem is that the Images are not optimized. How can I automatically replace all fetched tags with Next`s Image-Component? This is how I fetch the Html Code:
Blizii
  • 173
  • 11
4
votes
1 answer

Nextjs Image component complaining that the host is not added to config, but it is

I have a weeeeeeird issue with Nextjs, I have it connected to a cms (storyblok) and all images that I use come from that place. All images work just fine, but now I added a few new ones and I keep getting the error that the host is not configured,…
Darkbound
  • 3,026
  • 7
  • 34
  • 72
4
votes
1 answer

Don't display next/image component when the image doesn't exist

I'm using next/image and I want the image to not render at all when the path to the image is invalid, eg. the image doesn't exist. Now it displays the little icon and alt name. I don't want to display anything in that case. Is that possible? Since…
Filip
  • 855
  • 2
  • 18
  • 38
4
votes
1 answer

How to get image height and width properties in Next.js?

I just want to know how can we let an image take its own height and width using component in Next.js, instead of defining height and width by ourselves?
Harshita
  • 61
  • 1
  • 2
4
votes
1 answer

How to specify image height only and keep aspect ratio in Next.js?

I want to specify my image height only and keep the image aspect ratio without hardcoding the width. In a traditional img element I can do so: logo But if I try using next/image:
Kazuto_Ute
  • 679
  • 6
  • 20