"undefined is not a function" (or x is not a function) means the code tried to call something with () that isn't a function. Usually the name is misspelled, the method doesn't exist on that type of value (for example calling .map() on something that isn't a list), or the function comes from a library or script that didn't load, so it's undefined.
What's the problem
The console shows TypeError: undefined is not a function, x.map is not a function, or $ is not a function, and a feature stops working.
Why it happens
- A typo in the function or method name.
- The wrong type of value: calling a list method on an object, or on data the API returned in a different shape.
- A script or library didn't load, or loaded after the code that uses it.
- Two versions of a library conflicting, or a library's method renamed in a new version.
- An import or export mismatch in bundled code.
How to fix it
- Click the file and line in the console.
- Check the name for typos and that the method exists on that kind of value.
- Log the value just before the call to see what it actually is.
- If it's from a library, check the library's script loaded (Network tab) and before your code.
- If it started after an update, check the library's changelog for renamed or removed methods.
What Preventionlabs checks
One click runs the full report on your domain. For this problem it shows whether your site loads, how fast, and where its redirects go; script libraries on your homepage with published security holes; every outside service your homepage loads scripts and files from. With Cloudflare connected, it also shows recent deploys and account changes, with their times. It doesn't run your pages in a browser, so open the browser console on the failing page to see the error itself.
Run your free reportYour first report is free, no card needed. Then A$50 a month, up to 10 domains. Read-only: it never changes anything.
Sources
- MDN Web Docs: TypeError: "x" is not a functionreference
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value is not actually a function.