JavaScript TypeError: x is not a function — Check the Value Before Calling It
This error is different from is not defined: JavaScript found a value, but the value you tried to call is not actually a function.
TypeError: ... is not a function.The failing code uses parentheses like value() or object.method().The identifier exists, but its runtime value may be a string, object, undefined property or other non-callable value.Log the value and its type immediately before the failing call. This tells you whether the problem is the object, property name, import shape or overwritten variable.
console.log(value, typeof value);Verify: A callable function reports function. Any other type explains why the call fails.
Why this happens
MDN defines this TypeError as an attempt to call a value that is not a function. Common causes include a typo in a method name, calling a property that does not exist on that object type, or importing a module in a different shape than expected.
Diagnose before changing more
For example, array methods such as
map() are not available on plain objects.A later assignment can replace a function with a string, object or other value.
Default and named imports can produce a different runtime value than your code expects.
Fix #2 — correct the object or method being called
Confirm the receiver has the method you are invoking. If the value should be an array, function or class instance, trace where that value is created and validate its shape before the call.
if (typeof handler === 'function') {
handler();
}Verify: Run the same call again. The value immediately before the call should be the expected object/function type, and the original TypeError should be gone.
Fix #3 — align import/export shape and avoid name collisions
If the value comes from a module, verify whether it is a default export, named export or namespace object. Also check that a local variable has not reused the function’s name.
// named export
export function runTask() {}
import { runTask } from './task.js';Verify: Log the imported value once after changing the import. It should have the export shape you expect before you call it.
What not to do
Still seeing the error?
If the value is a function when logged but the error still appears elsewhere, inspect the exact stack trace. A different code path may be calling another property with the same name on a different object.
Official references
Still stuck? Ask the community
Share your operating system, software version, exact error text, and which fix you already tried. Another reader may have seen the same setup.
Loading community discussion…
Comments could not load here. Open ErrorHarbor Discussions on GitHub →