Sanity image src property error in Next.js Image component

15 replies
Last updated: Jan 28, 2026
Im trying to display an image like this
<Image src={product.images} width="200" height="200"objectFit="contain" alt=""/>
and it tells me this

Error: Image is missing required "src" property. Make sure you pass "src" in props to the `next/image` component. 
but the src is in there? what am I missing?
AI Update

The error you're seeing happens because product.images is likely a Sanity image object (containing metadata like _type, asset, etc.), not a plain URL string that Next.js Image expects.

Sanity stores images as structured objects, so you need to convert them to URLs first using the @sanity/image-url package.

Here's how to fix it:

1. Install the image URL builder:

npm install @sanity/image-url

2. Create a helper function (e.g., in lib/image.js or lib/sanity.js):

import imageUrlBuilder from '@sanity/image-url'
import { client } from './sanity' // your Sanity client

const builder = imageUrlBuilder(client)

export function urlFor(source) {
  return builder.image(source)
}

3. Use it in your component:

import { urlFor } from '@/lib/image'

<Image 
  src={urlFor(product.images).width(200).height(200).url()} 
  width={200} 
  height={200}
  objectFit="contain" 
  alt=""
/>

4. Configure Next.js to allow Sanity's CDN (in next.config.js):

module.exports = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'cdn.sanity.io',
      },
    ],
  },
}

The key is that urlFor(product.images).url() converts the Sanity image object into an actual URL string. You can also chain other transformations like .width(), .height(), .format('webp'), or .auto('format') for automatic format optimization based on browser support.

If product.images is an array of images, you'd need to access a specific one like urlFor(product.images[0]).url().

Show original thread
15 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?