Site build fails due to missing asset object in image parsing

6 replies
Last updated: Jun 26, 2024
Hi. I'm looking at a project for an old client where their site build fails. From what I can tell, it's because the images are not able to be parsed properly. The response JSON I see when debugging the site is missing the
asset
object.
This is what is received.

{
  file: {
    _type: 'image',
    altText: 'A cat'
  },
  _type: 'simpleImage',
  _key: '3b50e5688ba6'
}
When I inspect in their Studio, I can see the asset is present

{
        "_key": "3b50e5688ba6",
        "_type": "simpleImage",
        "file": {
          "_type": "image",
          "altText": "A cat",
          "asset": {
            "_ref": "image-319ffa6558ec64779833c8e624b0a871d2086190-5333x3000-jpg",
            "_type": "reference"
          }
        }
      }
Why might this be happening? When I last worked with them:
• They were on Sanity Studio v2 & haven't upgraded. Is this something to do with deprecation?
• They were on a free plan. Is this something that happens if they exceeded bandwidth or usage limits?
AI Update

This is almost certainly a GROQ projection issue where your query isn't including the nested asset field. The good news is this has nothing to do with Studio v2 deprecation or plan limits—it's just how the query is written.

The Problem

When you write a GROQ projection like this:

*[_type == "page"]{
  content[]{
    ...,
    file{
      altText
    }
  }
}

You're explicitly telling GROQ to only return altText from the file object. The asset reference gets excluded because you didn't ask for it in your projection.

The Solution

You need to explicitly include the asset field in your projection. Here are a few ways to fix it:

Option 1: Add the asset field explicitly

file{
  altText,
  asset
}

Option 2: Use the spread operator to get everything

file{
  ...
}

Option 3: Use the spread operator plus additional fields

file{
  ...,
  altText
}

The spread operator (...) includes all fields from the original document, so you'll get both asset and altText.

Why This Happens

GROQ projections are designed to give you precise control over what data gets returned, which optimizes response size and performance. When you specify a projection with { }, you're building a new object with only the fields you list. If you don't list asset, it won't be included—even though it exists in the Studio.

About Your Other Concerns

Studio v2: This isn't a deprecation issue. Studio v2 still works, though you should consider upgrading to Studio v3 when possible for better performance and features.

Free plan limits: Exceeding bandwidth or usage limits wouldn't cause missing fields in responses—you'd typically get rate limiting errors or service interruptions instead. The data structure itself wouldn't change.

Debugging Tip

Compare your GROQ query with what you see in the Studio's Vision plugin (or the data inspector). If fields appear in Vision but not in your build, the issue is definitely in how your query is projecting the data.

To clarify, their site is failing to build, not the Studio? Have I got that right?
user M
yes, that's right. There's a build step that checks for the file & asset property for images and that's failing as the asset property isn't present.
You’ll need to take a look at your frontend code and make sure you’re including the asset in your query.
Thanks. I made no changes to the code & it started working again.
Computers. 🤷‍♂️
Very strange!

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?