Errors / JavaScript errors
Uncaught TypeError: Cannot read properties of null (reading '…')
A script looked for something on the page that was not there, and stopped.
Everything after the failing line in that script stops, so a button, a menu or a form can quietly do nothing.
Why it happens
document.querySelector()orgetElementById()found nothing, usually because the element is on another page, was renamed, or is added later, and the code went on to use the result.- The script runs before the HTML it needs exists: a
<script>in the<head>withoutdefer, touchingdocument.bodyor a form that has not been parsed yet. - An API answered
nullfor a field the code expected to be an object.
How to fix it
- Read the property named in brackets:
(reading 'addEventListener')means the thing before.addEventListenerisnull. The stack's first line says which file and line. - Check the element exists before using it (
el?.addEventListener(…), or return early), or load the script withdeferso the HTML is there first. - If the script is shared by every page, guard the parts that only apply to some of them.
Whose problem it is
Either the site's own code or a third party's, depending on where it comes from.
Often seen with
- Cannot read properties of undefinedA script used a piece of data that had not arrived, or does not exist, and stopped.
- x is not a functionA script tried to use something as an action that is not one, and stopped.
On a site you look after, who tells you?
With Broken Here anyone clicks what is wrong and writes one sentence. Your developer gets a screenshot, the page, the browser, and the errors and failed requests recorded there. Free for one site.