👀 See Sanity in action: Watch product demo now →

Uncaught error - Could not resolve jsonType of undefined. No parent type found

23 replies
Last updated: Mar 18, 2021
Hi again. I have come upon another error I'm not sure about. After adding this:

marks: {
 annotations: [
  {
   name: "link",
   type: "externalLink",
   title: "Ekstern lenke",
  },
  {
   name: "internalLink",
   type: "internalLink",
   title: "Intern lenke",
  },
 ],
}
to the block type in an


of: [{ type: "block" }]
I get this error:


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 (&lt;anonymous&gt;)
    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 (&lt;anonymous&gt;)
    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)
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.
Mar 17, 2021, 11:25 AM
Are both
externalLink
and
internalLink
defined in your schema?
Mar 17, 2021, 11:28 AM
Yup.
Mar 17, 2021, 11:28 AM
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
What do you mean by “When used as its own type”?
Mar 17, 2021, 11:29 AM
as in, the type: "whatever name" field 😛
Mar 17, 2021, 11:30 AM
What do your definitions look like for those types?
Mar 17, 2021, 11:30 AM
{
 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
But neither of these correspond to the types you’re trying to use?
Mar 17, 2021, 11:33 AM
externalLink
and
internalLink
Mar 17, 2021, 11:34 AM
The top one is the one I replaced those two with to simplify
Mar 17, 2021, 11:34 AM
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 (&lt;anonymous&gt;)
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 (&lt;anonymous&gt;)
at validateSchema.js:61
at validateSchema.js:83
Mar 17, 2021, 11:35 AM
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
One moment
Mar 17, 2021, 11:36 AM
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
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
I can try setting up a stripped project.
Mar 17, 2021, 11:44 AM
Because I've no idea what is causing this.
Mar 17, 2021, 11:45 AM
Sure, that would likely be helpful
Mar 17, 2021, 11:49 AM
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:

marks: {
 annotations: [
  {
   name: "link",
   type: "externalLink",
   title: "Ekstern lenke",
  },
  {
   name: "internalLink",
   type: "internalLink",
   title: "Intern lenke",
  },
  ...,
 ],
}
to this:


import internalLink from "./internalLink"
import externalLink from "./externalLink"

...

marks: {
 annotations: [
  externalLink,
  internalLink,
  ...,
 ],
}
Mar 17, 2021, 10:02 PM
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
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!
Mar 18, 2021, 5:33 AM
Great! 🙌
Mar 18, 2021, 2:28 PM
🙂
Mar 18, 2021, 2:28 PM

Sanity.io – build remarkable experiences at scale

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