Uncaught error - Could not resolve jsonType of undefined. No parent type found

23 replies
Last updated: Mar 18, 2021
Hi again. I have come upon another error I'm not sure about. After adding this:

marks: {
 annotations: [
  {
   name: "link",
   type: "externalLink",
   title: "Ekstern lenke",
  },
  {
   name: "internalLink",
   type: "internalLink",
   title: "Intern lenke",
  },
 ],
}
to the block type in an


of: [{ type: "block" }]
I get this error:


Uncaught error
Could not resolve jsonType of undefined. No parent type found

Stack:

    at isJSONTypeOf (<http://localhost:3333/static/js/app.bundle.js:218462:11>)
    at <http://localhost:3333/static/js/app.bundle.js:218411:55>
    at Array.map (<anonymous>)
    at validateAnnotations (<http://localhost:3333/static/js/app.bundle.js:218399:22>)
    at validateMarks (<http://localhost:3333/static/js/app.bundle.js:218334:19>)
    at validateBlockType (<http://localhost:3333/static/js/app.bundle.js:218291:13>)
    at visitors.reduce._objectSpread._problems (<http://localhost:3333/static/js/app.bundle.js:217140:17>)
    at Array.reduce (<anonymous>)
    at <http://localhost:3333/static/js/app.bundle.js:217139:21>
    at <http://localhost:3333/static/js/app.bundle.js:217161:49>

(Your browsers Developer Tools may contain more info)
I've attempted to simplify the objects in annotations, but no matter what object i feed in, the end result is the same. Only way to stop getting it is to either not feed anything into annotations, or to use an inline object. But since my current project uses gatsby, inline objects aren't an option.
AI Update

The error you're encountering happens because when you reference annotation types by name (like type: "externalLink"), Sanity needs to find those type definitions in your schema, but they're not defined yet. The schema validation is looking for the actual type definitions but finding undefined.

Here's how to fix it:

Define Your Annotation Types First

You need to create the actual schema definitions for externalLink and internalLink as separate schema types before referencing them in your block configuration. Here's an example:

// In your schema files, define these as separate types:
export default {
  name: 'externalLink',
  type: 'object',
  title: 'External Link',
  fields: [
    {
      name: 'href',
      type: 'url',
      title: 'URL',
      validation: Rule => Rule.required()
    },
    {
      name: 'blank',
      type: 'boolean',
      title: 'Open in new tab',
      initialValue: true
    }
  ]
}
export default {
  name: 'internalLink',
  type: 'object',
  title: 'Internal Link',
  fields: [
    {
      name: 'reference',
      type: 'reference',
      title: 'Reference',
      to: [
        { type: 'page' }, // adjust to your document types
        { type: 'post' }
      ]
    }
  ]
}

Then make sure these types are included in your schema array when you create your Sanity schema.

Then Reference Them in Your Block

Once defined, your block configuration should work:

marks: {
  annotations: [
    {
      name: "link",
      type: "externalLink",
      title: "Ekstern lenke",
    },
    {
      name: "internalLink",
      type: "internalLink",
      title: "Intern lenke",
    },
  ],
}

The key issue is that Sanity's schema validation runs through all type references and tries to resolve them. When you use type: "externalLink", it looks for a schema type with name: "externalLink" but can't find it, resulting in the "Could not resolve jsonType of undefined" error during the validateAnnotations step.

You mentioned inline objects work but aren't an option with Gatsby - defining the types separately as shown above should resolve this while maintaining compatibility with your Gatsby setup. This is actually the recommended approach for custom annotations as it keeps your schema organized and reusable.

Are both
externalLink
and
internalLink
defined in your schema?
Yup.
Tried with just one placeholder item instead of those two, and while it worked inline, it did not when used as its own type.
What do you mean by “When used as its own type”?
as in, the type: "whatever name" field 😛
What do your definitions look like for those types?
{
 name: "potet",
 type: "sopp",
 title: "haha",
}

export default {
    name: "sopp",
    type: "object",
    title: "Sopp",
    fields: [
        {
            name: "stuing",
            type: "string",
            title: "Stuing",
        },
    ],
}

But neither of these correspond to the types you’re trying to use?
externalLink
and
internalLink
The top one is the one I replaced those two with to simplify
Error from console is potentially more descriptive:
isJSONTypeOf.js:16 Uncaught Error: Could not resolve jsonType of undefined. No parent type found
at isJSONTypeOf (isJSONTypeOf.js:16)
at block.js:167
at Array.map (&lt;anonymous&gt;)
at validateAnnotations (block.js:155)
at validateMarks (block.js:90)
at validateBlockType (block.js:47)
at visitors.reduce._objectSpread._problems (validateSchema.js:62)
at Array.reduce (&lt;anonymous&gt;)
at validateSchema.js:61
at validateSchema.js:83
If it works inline but not when you reference it via a string, it probably means that you haven’t defined the type in your schema correctly, but I can’t say without seeing the entire schema
One moment
aploogize for mess, this is my first sanity project
// First, we must import the schema creator
import createSchema from "part:@sanity/base/schema-creator"

// Then import schema types from any plugins that might expose them
import schemaTypes from "all:part:@sanity/base/schema-type"

import siteSettings from "./siteSettings"
import frontPage from "./frontPage"
import post from "./post"
import splitRow from "./splitRow"
import linkX from "./linkX"
import openingTime from "./openingTime"
import textSection from "./textSection"
import captionedImage from "./captionedImage"
import imageTextSection from "./imageTextSection"
import card from "./card"
import cardGallery from "./cardGallery"
import altImage from "./altImage"
import popBox from "./popBox"
import page from "./page"
import internalExternalLink from "./internalExternalLink"
import aFieldWithCondition from "./aFieldWithCondition"
import conditionalInput from "./conditionalInput"
import linkOptions from "./linkOptions"
import link from "./link"
import internalLink from "./internalLink"
import externalLink from "./externalLink"
import test from "./test"
import sopp from "./sopp"

// Then we give our schema to the builder and provide the result to Sanity
export default createSchema({
    // We name our schema
    name: "default",
    // Then proceed to concatenate our document type
    // to the ones provided by any plugins that are installed
    types: schemaTypes.concat([
        /* Your types here! */
        siteSettings,
        frontPage,
        post,
        splitRow,
        linkX,
        openingTime,
        textSection,
        captionedImage,
        imageTextSection,
        card,
        cardGallery,
        altImage,
        popBox,
        page,
        internalExternalLink,
        link,
        aFieldWithCondition,
        conditionalInput,
        linkOptions,
        internalLink,
        externalLink,
        test,
        sopp,
    ]),
})
That looks fine, but it might help to put the files that you suspect are causing problems in a github gist or something, bit difficult to diagnose from this.
I can try setting up a stripped project.
Because I've no idea what is causing this.
Sure, that would likely be helpful
Hi Are. The way you’re handling internalLink and externalLink (as imported objects), I think you’ll want to simply name them in your portable text schema. So you could try changing this:

marks: {
 annotations: [
  {
   name: "link",
   type: "externalLink",
   title: "Ekstern lenke",
  },
  {
   name: "internalLink",
   type: "internalLink",
   title: "Intern lenke",
  },
  ...,
 ],
}
to this:


import internalLink from "./internalLink"
import externalLink from "./externalLink"

...

marks: {
 annotations: [
  externalLink,
  internalLink,
  ...,
 ],
}
Alternatively, you could include them inline like Knut does here , where each (i.e., internalLink and externalLink) is an inline object.
Importing the objects worked perfectly. So the problem here was that, in annotations as opposed to a fields array, you need to do things differently. Whereas in fields, you can reference a type that has been imported in the schema without importing it in the actual file, in annotations that is not the case. The other issue, I guess, was that the error message wasn't helpful in this instance.
Anyway, it works now, so I'm happy! Thanks for all the help, guys!
Great! 🙌
🙂

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?