Errors / JavaScript errors
Uncaught ReferenceError: x is not defined
A script used a name nobody declared, usually because another script it depends on did not load first.
The script stops at that line; whatever it was about to set up does not happen.
Why it happens
- The script that defines it failed to load (a 404, a blocked domain) or loads after the one that uses it:
asyncscripts run in whatever order they arrive. - A typo, or a variable used outside the function where it was declared.
- Code written for Node (
require,process,module) running in the browser.
How to fix it
- Find where the name should come from and check that file loaded, in the network tab or in a Broken Here report's failed requests.
- Load dependencies in order: no
asyncon a script another one needs, ordeferon both. - Wrap optional third-party calls:
if (typeof gtag === "function") gtag(…).
Whose problem it is
Either the site's own code or a third party's, depending on where it comes from.
Does your site have it?
Free, no account. We open your page and four more in a clean Chrome and list every error like this one, with the page and the click that caused it. How the free page check works.
Often seen with
- $ / jQuery is not definedA script needs jQuery and ran before jQuery was on the page, or jQuery never loaded.
- google is not definedThe page tried to draw a Google map before Google's map script had loaded.
- process is not definedCode written for a server ran in the visitor's browser, where that part does not exist.
- require is not definedA file written for a server's module system was sent to the browser as it is.