question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'product' of null

See original GitHub issue

I’m seeing my Shopify products come through into Sanity via the webhook but whenever I add a product to a page and click it, I am met with the following error when navigating to the URL (/products/<slug>)

Server Error
TypeError: Cannot read property 'product' of null

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Source
pages/products/[slug].js (60:46) @ Product

  58 |   console.log(data)
  59 |   // set our Product state
> 60 |   const [product, setProduct] = useState(page.product)
     |                                              ^
  61 | 
  62 |   // find the default variant for this product by matching against the first product option
  63 |   const defaultVariant = page.product.variants?.find((v) => {

Is there something special I need to do for a Shopify product to have a “detail” page?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stephensilbercommented, Oct 4, 2021

Thanks for the link! I figured out that my issue was related to the isDraft flag in the above getProduct query (my client had uploaded all of their products but had not set them as active). I did try to pull in the latest changes via that stack overflow post but I was looking at ~35-40 files with merge conflicts so quickly gave up on that. Gonna mark this as closed…thanks again for the quick responses.

0reactions
ndimatteocommented, Oct 1, 2021

@stephensilber no problem!

Unfortunately, I don’t have any specific instructions on how to do that but perhaps this would help:

https://stackoverflow.com/questions/56577184/github-pull-changes-from-a-template-repository

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property of null - iDiallo
This error occurs when you read a property or call a method on a null object . That's because the DOM API returns...
Read more >
Uncaught TypeError: Cannot read property 'value' of null
I'm getting error in this code, I'm trying to do an event where in when the page is load, it will do the...
Read more >
TypeError: Cannot read property 'value' of Null in JS
To solve the "Cannot read property 'value' of null" error, make sure that the JS script tag is placed at the bottom of...
Read more >
How to deal with TypeError: cannot read properties of null
While coding in Javascript, you must have at least once received a Type Error which has the message “cannot read properties of null”....
Read more >
Unexpected error: Cannot read property 'products' of null #861
Describe the bug. It seems when we call collection by id, in case this collection is nonexistent, we've got the following error: ;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found