Sanity Studio: "Field not defined in schema" error for external link after deployment

9 replies
Last updated: Jan 18, 2022
Hey everyone, I'm trying to get external links working via the studio, following the guide here https://www.sanity.io/guides/portable-text-internal-and-external-links . When working locally I can see the option to "Open in new window" in the editor, but in the live studio it says:

This field is not defined in the schema, which could mean that the field definition has been removed or that someone else has added it to their own local project and have not deployed their changes yet.

Does anyone know why this is? I've deployed my changes so I'm not sure why it thinks it's not defined in the schema
🤔

blockContent.js
marks: {
        decorators: [
          { title: 'Strong', value: 'strong' },
          { title: 'Emphasis', value: 'em' },
        ],
        
        annotations: [
          {
            name: 'link',
            type: 'object',
            title: 'URL',
            fields: [
              {
                title: 'URL',
                name: 'href',
                type: 'url',
              },
              // External links
              {
                title: 'Open in new window',
                name: 'blank',
                type: 'boolean'
              }
            ],
          },
        ],
      },
AI Update

Based on your schema code, the issue is almost certainly that you haven't deployed your Studio changes to your hosted environment. When you see "This field is not defined in the schema" in your live Studio but it works locally, it means your local schema differs from what's deployed.

The sanity deploy command you ran deploys your Studio application (the interface itself), but it doesn't necessarily update the schema that other Sanity services see. However, for basic Studio functionality, deploying the Studio should be sufficient.

Here are the most likely causes and solutions:

1. Cache Issues After deploying, try these steps:

  • Hard refresh your browser (Ctrl+Shift+R or Cmd+Shift+R)
  • Clear your browser cache completely
  • Try accessing the Studio in an incognito/private window

2. Verify Your Deployment Make sure your deployment actually included the schema changes:

  • Check that your blockContent.js file is properly imported in your schema
  • Verify the file is in your repository and committed
  • Redeploy with sanity deploy to be certain

3. Check for Multiple Schema Definitions If you have the link annotation defined in multiple places in your schema, make sure they're all consistent. The deployed version might be picking up an older definition.

4. Schema Deployment (if using Canvas, Dashboard, or Agent Actions) If you're using newer Sanity features like Canvas or Agent Actions, you may also need to run:

sanity schema deploy

This is different from sanity deploy and makes your schema available to other Sanity apps beyond Studio. However, this typically isn't required for basic Studio functionality.

5. Verify Your Schema Syntax Your schema looks correct, but double-check that it's properly exported and imported into your main schema configuration file (usually schema.js or within your sanity.config.js).

The most common fix is simply a hard refresh after deployment, as browsers aggressively cache Studio assets. If that doesn't work, try redeploying and accessing from a private browsing window to rule out caching entirely.

Show original thread
9 replies
Is that the entirety of your file? It doesn't appear to be a default export. If you're calling for it in the main schema.js (or in a desk structure you've customized) it might not be able to import enough for the system to identify it and use it.
This is just what I thought was the relevant snippet. The entire file is:

export default {
  title: 'Block Content',
  name: 'blockContent',
  type: 'array',
  of: [
    {
      title: 'Block',
      type: 'block',
      styles: [
        { title: 'Normal', value: 'normal' },
        { title: 'H1', value: 'h1' },
        { title: 'H2', value: 'h2' },
        { title: 'H3', value: 'h3' },
        { title: 'H4', value: 'h4' },
        { title: 'Quote', value: 'blockquote' },
      ],
      lists: [{ title: 'Bullet', value: 'bullet' }],
      marks: {
        decorators: [
          { title: 'Strong', value: 'strong' },
          { title: 'Emphasis', value: 'em' },
        ],
        annotations: [
          {
            name: 'link',
            type: 'object',
            title: 'URL',
            fields: [
              {
                title: 'URL',
                name: 'href',
                type: 'url',
              },
              // External links
              {
                title: 'Open in new window',
                name: 'blank',
                type: 'boolean'
              }
            ],
          },
        ],
      },
    },
    {
      type: 'image',
      options: { hotspot: true },
    },
  ],
}
Ah, okay. Just checking. I went to text-compare.com and put yours on the left and mine on the right because I am literally using the same example live and it's working for me. Aside from validation, which shouldn't be relevant, we're doing the same thing. Pretty weird!
Hm, that is strange! What happens if you run
sanity undeploy
then
sanity deploy
once more?
should I run this locally?
Correct!
ahh you star!
that's fixed it, thanks both of you for your help!
Fantastic! I love when a redeploy magically fixes things 😅

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?