ErrorBellFree

Error library / this error

How to fix it

TypeError: x is not a function

What it means

You tried to call something as a function, but at that moment it is undefined, an object, or another type.

Common causes

  • A default import was written as a named import (or the other way round).
  • A callback prop was not passed, so calling it fails.
  • A method name is misspelled, or you called an array method on an object.
  • A library version changed an API.

How to fix it

1. Check the import style

If the module has a default export, import it without braces.

import debounce from 'lodash/debounce';   // default export
import { debounce } from 'lodash';          // named export

2. Call optional callbacks safely

Optional call syntax does nothing when the function is missing.

onSelect?.(item);

3. Print the type

The message names the variable, so log what it actually is.

console.log(typeof thing, thing);

Catch it the moment it happens

ErrorBell shows a dot on the page when this error occurs and takes you to the failing line, so you do not have to hunt through the console. Add it to Chrome, it is free.

Related errors