Uncaught error - Could not resolve jsonType of undefined. No parent type found
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.
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.