
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThis error occurs when you're trying to generate an image URL using the @sanity/image-url library, but the data structure being passed doesn't match what the library expects. Based on the error message showing an array structure, here are the most common causes and solutions:
Your error shows the image data wrapped in square brackets [{...}], indicating it's an array. The urlFor() function expects an object, not an array:
// ❌ Wrong - passing an array
urlFor([imageData])
// âś… Correct - passing the object directly
urlFor(imageData)If your image field is actually an array type in your Sanity schema, you need to access a specific image from that array or map through it:
// If image is an array, access the first image
urlFor(product.image[0])
// Or map through all images
{product?.image?.map(img => (
<img key={img._key} src={urlFor(img).url()} />
))}According to the Sanity documentation on presenting images, you need to expand the asset reference in your query:
// ❌ Wrong - doesn't expand the reference
*[_type == "post"] {
title,
image
}
// âś… Correct - expands the asset reference
*[_type == "post"] {
title,
image {
asset->
}
}Always check that the image data exists before trying to generate a URL:
{product.image?.asset && (
<img src={urlFor(product.image).url()} alt={product.title} />
)}The @sanity/image-url library expects an object with an asset property containing either a reference or the full asset object:
// With reference
{
asset: {
_ref: "image-85fd403b...",
_type: "reference"
}
}
// Or with expanded reference (using asset-> in query)
{
asset: {
_id: "image-85fd403b...",
url: "...",
// other asset properties
}
}Based on a community discussion that resolved this exact issue, the most common solution is:
asset->urlFor()The working code pattern looks like this:
{products?.map(product => (
<div key={product._id}>
<h1>{product?.title}</h1>
{product?.image?.map(image => (
<img key={image._key} src={urlFor(image).url()} alt="" />
))}
</div>
))}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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store