TypeError: Cannot read property of undefined

Hello Netlify team! Need some advice on how to tackle this error:

No problem during development, no problem during soft build. Only breaks on deploy to Netlify
netlify site name: risingrose.netlify.app

Hey there, thanks for reaching out.

What you are describing sounds a bit like a an issue with case sensitivity on our system.

Can you give this a read through and let us know if that fixes the issue?

Thanks for the quick reply, perry. Unless I’m missing something, it doesn’t appear to be the problem here.

Link to repo in case: https://github.com/Wyrd00/Gatsby-Contentful-V1/tree/comments

hi again! sorry you are still having trouble. looking at your build error more closely, i am seeing this in your log:

11:58:10 AM: indexedComments
11:58:10 AM: {}
11:58:11 AM: failed Building static HTML for pages - 1.107s
11:58:11 AM: error Building static HTML failed for path "/lilikoi-pound-cake/"
11:58:11 AM: 
11:58:11 AM:   13 |       console.log(`key: ${key}`, `comment: ${comment.message}`)
11:58:11 AM:   14 |       if (indexedComments && (indexedComments[key]['reply_to'] !== ''  && indexedComments[key]['reply_to'] !== undefined)) {
11:58:11 AM: > 15 |         indexedComments[indexedComments[key]['reply_to']].replies.push(comment)
11:58:11 AM:      |                                                           ^
11:58:11 AM:   16 |       }
11:58:11 AM:   17 |     }
11:58:11 AM:   18 |   }
11:58:11 AM: 
11:58:11 AM:   WebpackError: TypeError: Cannot read property 'replies' of undefined

this is very clearly the reason we aren’t able to complete your build - this is an unresolvable error we can’t get past.

I’m not sure exactly why - is there something unusual about that specific blog entry:

/lilikoi-pound-cake/ that is causing problems? :thinking:

In JavaScript almost everything is an object, null and undefined are exceptions. This error occurs when a property is read or a function is called on an undefined variable. Undefined means that a variable has been declared but has not been assigned a value. In JavaScript, properties and functions can only belong to objects. Since undefined is not an object type, calling a function or a property on such a variable causes the TypeError: Cannot read property of undefined.

The root cause of the error is that the declared variable doesn’t have any value, so by default, JavaScript treats all variables as undefined if you don’t assign the value. When you write the code, ensure that you have an if check added before accessing. This can be done in various ways. You can do if checks before dealing with objects whose values are bound to change:

if (myVar !== undefined) {
    ...
}

Or

if (typeof(myVar) !== 'undefined') {
    ...
}

Hi @gattingmk :wave:t6: welcome to the forums and thanks so much for sharing that with the community.