Sanity internalLink annotation error: "Could not resolve jsonType of undefined
I can see you're getting an error when trying to add an internal link annotation to block content. The error "Could not resolve jsonType of undefined" typically occurs when there's a mismatch in how you're defining and referencing your annotation type in the schema.
Looking at your code, the issue is with how you've structured your internalLink definition. You're using type: 'reference' at the top level, but annotations need to be defined as object types with fields inside them.
Based on the Sanity documentation on annotations, here's how to fix it:
Fix your separate internalLink type
Change your internalLink definition from using type: 'reference' directly to type: 'object' with a reference field inside:
import React from 'react';
export default {
title: 'Internal link to another document',
name: 'internalLink',
type: 'object', // Changed from 'reference' to 'object'
fields: [
{
name: 'reference',
type: 'reference',
title: 'Reference',
to: [{ type: 'page' }, { type: 'route' }],
}
],
components: { // Changed from 'blockEditor' to 'components'
annotation: ({ children }) => <span>{children} 🔗</span>
}
};Then in your block content schema, reference it like this:
marks: {
annotations: [
{
name: 'internalLink',
type: 'internalLink'
}
]
}Key changes explained
- Use
type: 'object': Annotations must be object types that can contain fields, not reference types directly at the top level - Add a
fieldsarray: Put your reference configuration inside a field within the object - Use
componentsinstead ofblockEditor: For Studio v3, the rendering customization uses thecomponentsproperty with anannotationkey
Alternative: Define inline
If you prefer not to have a separate file, you can define the annotation directly in your block content schema:
marks: {
annotations: [
{
name: 'internalLink',
type: 'object',
title: 'Internal link',
icon: () => '🔗',
fields: [
{
name: 'reference',
type: 'reference',
to: [{ type: 'page' }, { type: 'route' }]
}
],
components: {
annotation: (props) => <span>{props.children} 🔗</span>
}
}
]
}The error you were seeing happened because the schema validator couldn't understand the structure when reference was used as the top-level type for an annotation. Wrapping it in an object type with fields resolves this issue.
Show original thread4 replies
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.