Uncaught error - Could not resolve jsonType of undefined. No parent type found
23 replies
Last updated: Mar 18, 2021
A
Hi again. I have come upon another error I'm not sure about. After adding this:
to the block type in an
I get this error:
I've attempted to simplify the objects in annotations, but no matter what object i feed in, the end result is the same. Only way to stop getting it is to either not feed anything into annotations, or to use an inline object. But since my current project uses gatsby, inline objects aren't an option.
marks: { annotations: [ { name: "link", type: "externalLink", title: "Ekstern lenke", }, { name: "internalLink", type: "internalLink", title: "Intern lenke", }, ], }
of: [{ type: "block" }]
Uncaught error Could not resolve jsonType of undefined. No parent type found Stack: at isJSONTypeOf (<http://localhost:3333/static/js/app.bundle.js:218462:11>) at <http://localhost:3333/static/js/app.bundle.js:218411:55> at Array.map (<anonymous>) at validateAnnotations (<http://localhost:3333/static/js/app.bundle.js:218399:22>) at validateMarks (<http://localhost:3333/static/js/app.bundle.js:218334:19>) at validateBlockType (<http://localhost:3333/static/js/app.bundle.js:218291:13>) at visitors.reduce._objectSpread._problems (<http://localhost:3333/static/js/app.bundle.js:217140:17>) at Array.reduce (<anonymous>) at <http://localhost:3333/static/js/app.bundle.js:217139:21> at <http://localhost:3333/static/js/app.bundle.js:217161:49> (Your browsers Developer Tools may contain more info)
Mar 17, 2021, 11:25 AM
R
Are both
externalLinkand
internalLinkdefined in your schema?
Mar 17, 2021, 11:28 AM
A
Yup.
Mar 17, 2021, 11:28 AM
A
Tried with just one placeholder item instead of those two, and while it worked inline, it did not when used as its own type.
Mar 17, 2021, 11:29 AM
R
What do you mean by “When used as its own type”?
Mar 17, 2021, 11:29 AM
A
as in, the type: "whatever name" field 😛
Mar 17, 2021, 11:30 AM
R
What do your definitions look like for those types?
Mar 17, 2021, 11:30 AM
A
{ name: "potet", type: "sopp", title: "haha", }
export default { name: "sopp", type: "object", title: "Sopp", fields: [ { name: "stuing", type: "string", title: "Stuing", }, ], }
Mar 17, 2021, 11:31 AM
R
But neither of these correspond to the types you’re trying to use?
Mar 17, 2021, 11:33 AM
R
externalLinkand
internalLink
Mar 17, 2021, 11:34 AM
A
The top one is the one I replaced those two with to simplify
Mar 17, 2021, 11:34 AM
A
Error from console is potentially more descriptive:
isJSONTypeOf.js:16 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:83
isJSONTypeOf.js:16 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:83
Mar 17, 2021, 11:35 AM
R
If it works inline but not when you reference it via a string, it probably means that you haven’t defined the type in your schema correctly, but I can’t say without seeing the entire schema
Mar 17, 2021, 11:36 AM
A
One moment
Mar 17, 2021, 11:36 AM
A
aploogize for mess, this is my first sanity project
// First, we must import the schema creator import createSchema from "part:@sanity/base/schema-creator" // Then import schema types from any plugins that might expose them import schemaTypes from "all:part:@sanity/base/schema-type" import siteSettings from "./siteSettings" import frontPage from "./frontPage" import post from "./post" import splitRow from "./splitRow" import linkX from "./linkX" import openingTime from "./openingTime" import textSection from "./textSection" import captionedImage from "./captionedImage" import imageTextSection from "./imageTextSection" import card from "./card" import cardGallery from "./cardGallery" import altImage from "./altImage" import popBox from "./popBox" import page from "./page" import internalExternalLink from "./internalExternalLink" import aFieldWithCondition from "./aFieldWithCondition" import conditionalInput from "./conditionalInput" import linkOptions from "./linkOptions" import link from "./link" import internalLink from "./internalLink" import externalLink from "./externalLink" import test from "./test" import sopp from "./sopp" // 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! */ siteSettings, frontPage, post, splitRow, linkX, openingTime, textSection, captionedImage, imageTextSection, card, cardGallery, altImage, popBox, page, internalExternalLink, link, aFieldWithCondition, conditionalInput, linkOptions, internalLink, externalLink, test, sopp, ]), })
Mar 17, 2021, 11:38 AM
R
That looks fine, but it might help to put the files that you suspect are causing problems in a github gist or something, bit difficult to diagnose from this.
Mar 17, 2021, 11:43 AM
A
I can try setting up a stripped project.
Mar 17, 2021, 11:44 AM
A
Because I've no idea what is causing this.
Mar 17, 2021, 11:45 AM
R
Sure, that would likely be helpful
Mar 17, 2021, 11:49 AM
G
Hi Are. The way you’re handling internalLink and externalLink (as imported objects), I think you’ll want to simply name them in your portable text schema. So you could try changing this:
to this:
marks: { annotations: [ { name: "link", type: "externalLink", title: "Ekstern lenke", }, { name: "internalLink", type: "internalLink", title: "Intern lenke", }, ..., ], }
import internalLink from "./internalLink" import externalLink from "./externalLink" ... marks: { annotations: [ externalLink, internalLink, ..., ], }
Mar 17, 2021, 10:02 PM
G
Alternatively, you could include them inline like Knut does here , where each (i.e., internalLink and externalLink) is an inline object.
Mar 17, 2021, 10:32 PM
A
Importing the objects worked perfectly. So the problem here was that, in annotations as opposed to a fields array, you need to do things differently. Whereas in fields, you can reference a type that has been imported in the schema without importing it in the actual file, in annotations that is not the case. The other issue, I guess, was that the error message wasn't helpful in this instance.
Anyway, it works now, so I'm happy! Thanks for all the help, guys!
Anyway, it works now, so I'm happy! Thanks for all the help, guys!
Mar 18, 2021, 5:33 AM
G
Great! 🙌
Mar 18, 2021, 2:28 PM
A
🙂
Mar 18, 2021, 2:28 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.