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
16
votes
4 answers

Types of property 'src' are incompatible in nextjs/image

I am using react dropzone to upload multi-image in my simple application. For showing which type of images are drop for that I make a separate component with TypeScript. But Next.js image src is showing error like Type: '{ src: string; alt: string;…
Arif hossain
  • 439
  • 2
  • 6
  • 8
14
votes
2 answers

How to use Next JS IMAGE inside material ui card media

I am using Next JS and Material UI together in my project. for Image optimization, I would like to use the Next JS Image component. currently, my card media looks like below. I am getting the image URL row.image.url from an API call and assigning it…
12
votes
2 answers

How to display a placeholder while the image is loaded in Next.Js?

I'm getting some images from Firebase using getStaticProps, and then displaying them with next Image component. However, they take a while to display, how can I display a placeholder while they haven't loaded?
João Pedro
  • 794
  • 2
  • 12
  • 28
12
votes
4 answers

next/image not working with props as image source

My Home page sends data from my strapi cms to my PostSlider component via props import React from "react"; import styles from './index.module.scss' import { AxiosService } from '../utils/axios-service' import PostSlider from…
dev_el
  • 2,357
  • 5
  • 24
  • 55
11
votes
3 answers

How to export static images on Nextjs?

when I want to export my nextjs app, it says that I cannot export my images on static websites. Error: Image Optimization using Next.js' default loader is not compatible with next export. Possible solutions: - Use next start to run a server, which…
Cesarioo
  • 113
  • 1
  • 1
  • 5
11
votes
5 answers

Next Image, image disappears with layout responsive

I'm trying to add the Next Image component to my project. And I have a problem, the image disappears when I add layout='responsive'. code: navbar-logo
Marko B.
  • 535
  • 3
  • 8
  • 18
11
votes
5 answers

Error: Invalid src prop on `next/image`, hostname "res.cloudinary.com" is not configured under images in your `next.config.js`

I'm creating an array of objects where I have an image src property whose name is coverSrc, and I'm exporting & importing it into my main component. In my main component, I m using the Material UI CardMedia component to display images. but it gives…
Arif hossain
  • 439
  • 2
  • 6
  • 8
11
votes
4 answers

How can I add a fade-in animation for Nextjs/Image when it loads?

I'm using next/image, which works great, except the actual image loading in is super jarring and there's no animation or fade in. Is there a way to accomplish this? I've tried a ton of things and none of them work. Here's my code:
Citizen
  • 12,430
  • 26
  • 76
  • 117
11
votes
2 answers

Using the new Next.js Image component with Material UI

In Material UI the components that display images have a parameter for the image. eg: In Next.js v10 there is a new Image component that automatically scales…
terchris
  • 545
  • 6
  • 16
10
votes
0 answers

Img srcset with sizes not working as expected with responsive next/image being shipped on simulated mobile screen in chromium

What did I do? Setup a NextJs project to ship different image sizes for different screens sizes with the help of next/image component with the following settings: {title}
LHC
  • 101
  • 5
9
votes
2 answers

How to override Next.js `*.svg` module declaration?

Next.js has recently made a modification (in v11.0.x) which has the following type definitions: In next-env.d.ts (non-modifiable, regenerated at every build): /// /// ///
brc-dd
  • 10,788
  • 3
  • 47
  • 67
9
votes
4 answers

Getting NextJS Image Component & @svgr/webpack to play nicely together

I have a Next.js site with the @svgr/webpack library installed. I have configured next.config.js to work with @svgr/webpack and now want to import an svg image and use it with the new next/image component. Here is how I set up my next.config.js…
Moshe
  • 6,011
  • 16
  • 60
  • 112
9
votes
5 answers

Next.js public images not showing in production build

I have a Next.js app I am deploying to Heroku. When I dev locally I see the images, but when I push to Heroku and check the site, the images have a 404. I have a public folder where I have the images (.png) right in the folder, and the code I…
Chipe
  • 4,641
  • 10
  • 36
  • 64
9
votes
3 answers

Install sharp without GitHub fetch for Nextjs: Error: Cannot find module 'sharp'

I'm trying to use Next.js on my corporate system, but whenever I run "npm run build", the build fails with the message: Error: Cannot find module 'sharp' I tried installing sharp but I get this error: info sharp Downloading…
Abhijeet Singh
  • 994
  • 11
  • 27
9
votes
2 answers

How to run a function onLoad of an image in NextJS Image component

I want to show a skeleton while my image is loading. I tried to pass an onLoad prop in the new Image component provided by NextJS but the function fires off before the image is loaded. Here is my code const [loaded, setLoaded] =…
angelo
  • 2,661
  • 3
  • 16
  • 22
1
2
3
20 21