Storefront error library · JavaScript · Reviewed November 15, 2026
Cannot read properties of undefined (or null)
on a Shopify store.
TypeError: Cannot read properties of undefined or null, and its Safari form "undefined is not an object". Why Shopify themes throw it, which buttons it breaks and how to fix it.
The short answer
Theme or app code used something that was not there: a missing element, variant or object. Often more than any other JavaScript error. When it is thrown inside the product form, variant picker or cart drawer, the click does nothing and the shopper sees no message. Safari-only forms of it point at an iPhone segment, which on many stores is most of the mobile revenue.
At a glance
Cannot read properties of undefined (or null) in three lines.
| Who can fix it | Your theme developer, or the app whose file is in the stack |
|---|---|
| Does it cost sales? | Often, when thrown in the product form, variant picker or cart |
| What Dozenfold does with it | Opens an issue with the stack mapped to theme source and the orders lost per day |
| Group | JavaScript |
| Last reviewed |
What you see
The exact messages.
The same problem is worded differently by each browser and tool. Search your console and error tracker for all of them.
What it means
In plain English.
JavaScript tried to read a property from a value that was undefined or null. The word in brackets, or after “evaluating”, is the property it wanted; the value in front of it is what was missing.
The same mistake reads differently in each browser. Chrome and Edge say “Cannot read properties of”, Safari says “is not an object”, Firefox says “can’t access property”. Count them together when you judge how often it happens.
Does it cost sales?
Which steps it can break.
When it happens on the path to purchase, look first at:
- Add to cart and Buy it now
- Variant and quantity selectors
- Cart drawer quantity changes and removal
- Checkout button in the cart
Why it happens on Shopify
The usual causes.
An element that is not on this page
document.querySelector returns null when a section is missing from a template, was removed in the theme editor, or had its class renamed. The script still runs on every page.
A variant that does not exist
Variant pickers look up the selected options in the product JSON. A sold-out, deleted or unavailable combination returns undefined, and the next line reads variant.id.
Code that runs too early
A script without defer runs before the HTML below it exists, so its elements are null.
DOM replaced after a cart update
Themes that re-render sections through the Section Rendering API replace the HTML; listeners and references to the old nodes point at nothing.
An app removed or changed
Theme code that calls an app’s global object breaks when the app is uninstalled or changes its script.
Real problem or noise?
Check this before anyone debugs.
Most stores log this error at some level. These signals tell you whether real shoppers are affected.
- RealThe stack points at your theme’s product, variant or cart code.
- RealIt began with a theme publish or an app update.
- NoiseThe stack runs through a browser extension, or only one in-app browser hits it.
How to fix it
Reproduce, then fix.
- 01
Find the line
Reproduce in DevTools with “Pause on uncaught exceptions” on. If the file is minified, use the theme’s unminified source or a source map. Note the page template and the variant selected.
- 02
Guard the lookup
Check for the element or variant before using it, and stop quietly on pages where it does not apply.
const form = document.querySelector('product-form form'); if (!form) return; const variant = product.variants.find((v) => v.id === selectedId); if (!variant?.available) { showMessage('This option is sold out.'); return; } - 03
Load scripts with defer
Add defer to theme scripts in theme.liquid or section files so they run after the HTML is parsed.
- 04
Re-bind after section rendering
After replacing HTML from the Section Rendering API, attach listeners again, or use event delegation on a parent that is never replaced.
Find it automatically
Know which errors cost orders.
Dozenfold groups the error by where it was thrown, so each repeat lands in one issue with the browsers, devices and page groups it hits and the shopper step it happened on. With theme access allowed, each theme publish is a release marker, and Shopify’s theme source maps are stored on publish so the stack points at your theme source.
Each issue is compared with clean sessions at the same step to estimate the orders it costs per day, with a 95% interval, so a null error in the cart drawer ranks above the same error on a blog template.
14-day trial · From $49 a month · Billed through Shopify
Questions
Cannot read properties of undefined (or null): FAQ.
What is the difference between undefined and null in this error?
undefined usually means a value was never set or a lookup found nothing, such as a missing variant. null usually comes from the DOM: querySelector found no element. The fix is the same: check before you read.
Why does it only happen on Safari?
Often it is the same bug, worded “undefined is not an object”. If it really is Safari-only, look for browser APIs Safari lacks or behaves differently with, or for code that depends on load timing.
Is it caused by an app or by my theme?
Look at the file in the stack. Files from your store domain’s theme assets are the theme’s; files from an app’s host are the app’s. Theme code calling an app’s global object that is gone is still a theme fix.
Does optional chaining fix it?
It stops the throw. Make sure the feature still does something sensible, such as showing “sold out”, instead of failing silently.
Written by the Dozenfold team, who build storefront error monitoring for Shopify. Reviewed November 15, 2026 against MDN: TypeError “x is undefined / null” and Shopify: Section Rendering API.