Cannot read property 'product' of null
See original GitHub issueI’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:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the link! I figured out that my issue was related to the
isDraft
flag in the abovegetProduct
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.@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