Register now - Learn how Tecovas roped in success with Sanity and Shopify 🤠

Issue with using the plugin `block-content-to-react` in Gatsby causing an error with formatted text.

13 replies
Last updated: Mar 11, 2021
Hey everyone. Has anyone successfully used the plugin
? I keep getting the error
Cannot read property 'find' of undefined
when it’s used with any formatted text (bold/italics/underline). If the content of the block is plain it works fine.
Mar 11, 2021, 3:00 PM
This is the error I’m getting in Gatsby 🤕
Mar 11, 2021, 3:01 PM
Hi User. I think you’ll also want to use the gatsby-source-sanity plugin.
Mar 11, 2021, 3:24 PM
Hey User. I’m using that plugin too. Everything else is working great (querying and using strings/images etc.)
Mar 11, 2021, 3:26 PM
I came across this same error with someone using Nuxt, and it was a cache problem. Would you mind trying
gatsby clean
to clear the cache? I’m doubtful but it shouldn’t hurt to try.
Mar 11, 2021, 3:38 PM
Unfortunately that didn’t help with the error 😞
Mar 11, 2021, 3:42 PM
Thanks for trying. Your portable text component looks something like this?
Mar 11, 2021, 3:45 PM
Yes, and then I’m using the component like this:
<PortableText blocks={props.description} />
. The problem seems to be coming from how the plugin processes the ‘marks’ field. As soon as I remove this from my GraphQL query I no longer get the error (but then the text has no formatting applied)
Mar 11, 2021, 4:01 PM
What if you use
instead of
Mar 11, 2021, 4:40 PM
I get this error unfortunately
Mar 11, 2021, 5:01 PM
My GraphQL query looks like this:
query MyQuery {
  allSanityProject {
    nodes {
      description {
        children {
And I’m passing the description into the PortableText component’s
Mar 11, 2021, 5:04 PM
With Gatsby you probably want to use the
field in this case, so it includes all the available fields (
is missing above because of GraphQL schema inference issues):
Mar 11, 2021, 5:10 PM
This worked! Thank you so much! And User, thank you for all of your help too, I really appreciate your time 🙌
Mar 11, 2021, 5:19 PM
Happy to hear it, User!
Mar 11, 2021, 5:20 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?

Categorized in