🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Error encountered when using a top-level schema in Sanity.io

1 replies
Last updated: May 31, 2022
Hi everybody, I’m finding this error:
Error: Encountered anonymous inline image "image" for field/type "ImageWithAlt".
I’ve run into this issue before and the error advises I need to create a top-level schema. I have resolved this in the past by bringing my repeatable content up into my component folder, like this:
export default {
    name: 'ImageWithAlt',
    title: 'Image with Alternative Text',
    type: 'object',
    fields: [
        { 
            name: 'image', 
            title: 'Image', 
            type: 'image',
            options: {
                hotspot: true
            },
            fields: [
                    {
                        name: 'alt',
                        title: 'Alternative text',
                        type: 'string',
                        options: {
                            isHighlighted: true
                    }
                }
            ]  
        },
    ]
}
Then, I use it as a type in my schema:

export default {
    name: 'layoutHeader',
    title: 'Layout Header',
    type: 'document',
    icon,
    fields: [
      { 
        name: 'title', 
        title: 'Title', 
        type: 'string' 
      },
      { 
        name: 'mainlogo', 
        title: 'Logo with Alt Text', 
        type: 'ImageWithAlt',

      },
      {
        name: 'contactnumber',
        title: 'Contact Number',
        type: 'string',
      },
    ],
  }
However, this time I get the same error when I run
sanity graphql deploy
from the CLI. I have been tinkering with it to figure out what’s wrong, but I think I could use some fresh eyes on it. Can anyone tell me what little gotcha I’m missing?
May 31, 2022, 3:41 PM
Got it, I had an extra layer. So my component needed to be this:
export default {
    name: 'ImageWithAlt',
    title: 'Image with Alternative Text',
    type: 'image',
    options: {
        hotspot: true
    },
    fields: [
            {
                name: 'alt',
                title: 'Alternative text',
                type: 'string',
                options: {
                    isHighlighted: true
            }
        }
    ]  
}
May 31, 2022, 4:11 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?