🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Error when hoisting annotation to its own type in Slack thread.

8 replies
Last updated: Jun 1, 2021
Adding an object to annotations in a block is throwing an error when I hoist the annotation to it’s own type.

Uncaught errorCould not resolve jsonType of undefined. No parent type found


annotations: [

{

name: "href",

title: "URL",

type: "externalLink",

icon: MdLink

}

],

It’s referencing this simple object as a test.


export default {

name: 'externalLink',

title: 'External Link',

type: 'object',

fields: [

{

name:'foo',

title: 'foo',

type: 'string'

}

]

}


If I simply add the annotation in-line everything works fine.


annotations: [

{

name: "color",

title: "Text Color",

type: "color",

icon: MdFormatColorText,

},

{

name: 'externalLink',

title: 'External Link',

type: 'object',

fields: [

{

name:'foo',

title: 'foo',

type: 'string'

}

]

}

]


Any suggestions?
Jun 1, 2021, 3:57 PM
Hey User! Just to double check, did you add
externalLink
to your schema.js? If that’s not the issue, I believe that adding a new parameter (
icon
) may actually create a new type.
Jun 1, 2021, 5:36 PM
I did, however I noticed the following….
Jun 1, 2021, 5:37 PM
This is how I’m importing objects into my schema
Jun 1, 2021, 5:38 PM
// Object Types

import * as objects from './objects'

const allObjects = Object.values(objects).map((myObject) => {

return { ...myObject }

})
Jun 1, 2021, 5:38 PM
_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! */

page,

section,

sectionBlock,

config,

theme,

nav,

sponsor,

])

.concat(allObjects)

.concat(allSections)

.concat(allConfigs)

.concat(allPlugs)

})
Jun 1, 2021, 5:39 PM
I just tried to import it manually into the file without using the allObjects constant and it worked. So that looks like the following, but it feels like a workaround.
Jun 1, 2021, 5:40 PM
// Manual object imports

import link from './objects/link'




// 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! */

page,

section,

sectionBlock,

config,

theme,

nav,

sponsor,

link,

// backgroundImage,

// simpleBlockContent,

// palette,

// typography,

])

.concat(allObjects)

.concat(allSections)

.concat(allConfigs)

.concat(allPlugs)

})
Jun 1, 2021, 5:41 PM
I’m really confused why manually importing works while using the allObject constant doesn’t.
Jun 1, 2021, 5:42 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?