Sanity internalLink annotation error: "Could not resolve jsonType of undefined
annotations: [{ type: 'internalLink' }] studio trow me error:Uncaught error
Could not resolve jsonType of undefined. No parent type found
Stack:
at isJSONTypeOf (<http://localhost:3333/studio/static/js/app.bundle.js:231611:11>)
at <http://localhost:3333/studio/static/js/app.bundle.js:231560:55>
at Array.map (<anonymous>)
at validateAnnotations (<http://localhost:3333/studio/static/js/app.bundle.js:231548:22>)
at validateMarks (<http://localhost:3333/studio/static/js/app.bundle.js:231483:19>)
at validateBlockType (<http://localhost:3333/studio/static/js/app.bundle.js:231440:13>)
at visitors.reduce._objectSpread._problems (<http://localhost:3333/studio/static/js/app.bundle.js:230289:17>)
at Array.reduce (<anonymous>)
at <http://localhost:3333/studio/static/js/app.bundle.js:230288:21>
at <http://localhost:3333/studio/static/js/app.bundle.js:230310:49>
(Your browsers Developer Tools may contain more info)import React from 'react';
const InternalLinkRender = ({ children }) => <span>{children} 🔗</span>;
export default {
title: 'Internal link to another document',
name: 'internalLink',
type: 'reference',
description: 'Locate a document you want to link to',
to: [{ type: 'page' }, { type: 'route' }],
blockEditor: {
icon: () => '🔗',
render: InternalLinkRender,
},
};Uncaught Error: Could not resolve jsonType of undefined. No parent type found
at isJSONTypeOf (isJSONTypeOf.js:16)
at block.js:167
at Array.map (<anonymous>)
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 (<anonymous>)
at validateSchema.js:61
at validateSchema.js:83I 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
Was this answer helpful?
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.