Error installing "stablo" template, resolved with code change.

4 replies
Last updated: Oct 17, 2022
Hello people,I’m new here and I hope I could get some help.
I’m trying to install the template “stablo” but I keep on running into a problem in components/postlist.js (67:27) @ PostList:



<div className="flex items-center gap-3">

66 |             <div className="relative flex-shrink-0 w-5 h-5">

> 67 |               {post.author.image && (

|                           ^

68 |                 <Image

69 |                   src={AuthorimageProps.src}

70 |                   blurDataURL={AuthorimageProps.blurDataURL}


Any idea?
Any suggestion is welcome.
Thanks!
AI Update

I can see you're getting an error where post.author.image is undefined or null when the PostList component tries to render. This is a common issue with the Stablo template that typically happens when the GROQ query fetching your posts isn't properly populating the author's image data.

Here are the most likely solutions:

1. Check your GROQ query The most common cause is that your GROQ query in the page or component isn't using a reference expansion for the author field. Look for where posts are being fetched (likely in getStaticProps or a data fetching function) and make sure the query expands the author reference and includes the image:

// Instead of just "author"
*[_type == "post"] {
  ...,
  author->  // This expands the reference
}

// Make sure it includes the image field
*[_type == "post"] {
  ...,
  author-> {
    name,
    image
  }
}

2. Add a safety check As a quick fix, you can add optional chaining to prevent the error:

{post?.author?.image && (
  <Image
    src={AuthorimageProps.src}
    blurDataURL={AuthorimageProps.blurDataURL}

3. Verify your content Check in your Sanity Studio that:

  • The post actually has an author assigned
  • That author document has an image field populated
  • The image field in your author schema is properly configured

4. Check the AuthorimageProps function Make sure the function that generates AuthorimageProps is correctly handling the post.author.image object. It should be using Sanity's image URL builder properly.

The Stablo template has had some reported issues with initial setup, so if you're still stuck, you might want to check the Stablo GitHub repository for any recent updates or issues that match yours. The template maintainers may have already addressed this in a newer version.

If none of these work, share your GROQ query and I can help you debug it further!

youre showing the code point the error is coming from, but not the error message. What is the error message?
Sorry:
error - TypeError: Cannot read properties of null (reading 'image')
    at PostList (webpack-internal:///./components/postlist.js:140:59)
    at renderWithHooks (/Users/marioparra/websites/stablo-1.0.0/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5658:16)
    at renderIndeterminateComponent (/Users/marioparra/websites/stablo-1.0.0/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5731:15)
    at renderElement (/Users/marioparra/websites/stablo-1.0.0/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5946:7)
    at renderNodeDestructiveImpl (/Users/marioparra/websites/stablo-1.0.0/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6104:11)
    at renderNodeDestructive (/Users/marioparra/websites/stablo-1.0.0/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6076:14)
    at renderNode (/Users/marioparra/websites/stablo-1.0.0/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6259:12)
    at renderChildrenArray (/Users/marioparra/websites/stablo-1.0.0/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6211:7)
    at renderNodeDestructiveImpl (/Users/marioparra/websites/stablo-1.0.0/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6141:7)
    at renderNodeDestructive (/Users/marioparra/websites/stablo-1.0.0/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6076:14) {
apparently your post doesnt have an author
You could change the code to
post?.author?.image
, though it might also be a problem with your content/CMS if yours shouldalways have an author
Woooow, thanks a lot. That solved the problem for me! 🙂

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.

Was this answer helpful?