Error when hoisting annotation to its own type in Slack thread.
The error you're encountering is a common schema registration issue. When you reference a custom type like externalLink in your annotations, Sanity needs to know about that type definition beforehand. The type must be registered in your schema before it can be referenced.
The key issue is that your externalLink type definition needs to be included in your schema's types array. When you define it inline, Sanity automatically registers it, but when you extract it to its own file, you need to explicitly add it to your schema configuration.
Here's how to fix it:
1. Make sure your externalLink type is exported from its file:
// schemas/externalLink.js (or .ts)
export default {
name: 'externalLink',
title: 'External Link',
type: 'object',
fields: [
{
name: 'foo',
title: 'Foo',
type: 'string'
}
]
}2. Import and register it in your main schema configuration:
// sanity.config.js (or schema/index.js depending on your setup)
import externalLink from './schemas/externalLink'
import yourBlockContentType from './schemas/yourBlockContentType'
export default defineConfig({
// ... other config
schema: {
types: [
externalLink, // Register the type here BEFORE using it
yourBlockContentType,
// ... other types
],
},
})3. Now reference it in your annotations:
annotations: [
{
name: "href",
title: "URL",
type: "externalLink", // This will now resolve correctly
icon: MdLink
}
]The error "Could not resolve jsonType of undefined. No parent type found" occurs because Sanity is trying to find a type called externalLink but can't find it in the registered schema types. By adding it to the types array in your schema configuration, you're making it available for reference throughout your schema.
This is the standard pattern for all custom types in Sanity - whether for annotations, regular fields, or references. All custom types must be registered in the schema before they can be referenced elsewhere. The inline version works because Sanity automatically registers inline type definitions within the context where they're used.
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.