# TypeError: x is not a function

**Code:** `TypeError: not a function` · **Category:** JavaScript · **Seen on:** JavaScript, Node.js

You called something as a function, but its value is not a function (it’s undefined, a string, an object…).

## Meaning

The value exists (or is undefined) but isn’t callable. Common with wrong imports, calling array methods on non-arrays, or a variable shadowing a function.

## Common causes

- Wrong import (default vs named): `import foo from` vs `import { foo } from`
- Calling `.map`/`.forEach` on an object or string instead of an array
- Typo in method name, or method doesn’t exist in this library version
- Variable reassigned/shadowed with a non-function
- Missing semicolon before a line starting with `(` (ASI issue)
- Calling a jQuery plugin before it loaded

## Quick fix

1. Log `typeof x` right before the call
2. Check the import style against the library docs
3. Use `Array.isArray(data)` before array methods; for objects use `Object.values(obj).map(...)`

## Detailed fix by platform

### JavaScript

1. Default vs named exports:

```javascript
// utils.js: export function formatDate() {}
import formatDate from './utils.js';     // ❌ undefined → "formatDate is not a function"
import { formatDate } from './utils.js'; // ✅
```


### Node.js

1. CommonJS/ESM interop: `const x = require('pkg').default` may be needed for ESM default exports.

## How to diagnose

1. **Value** — What is typeof the thing being called?
2. **Import** — Named or default export?
3. **Version** — Does this method exist in the installed version?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/javascript/typeerror-is-not-a-function)
