TypeError: not a function JavaScript Origin: On your device Last updated 14 Oct 2026

TypeError: x is not a function

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

Exact message you may see is not a functionTypeError: x is not a functionmap is not a functionforEach is not a function$ is not a function
Seen on: JavaScript Node.js

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?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

22021 — ERROR: invalid byte sequence for encoding "UTF8": 0x00 (PostgreSQL)22021AttributeError — AttributeError: 'X' object has no attribute 'y' (Python)AttributeErrordeclared and not used — Go: declared and not used: x / "fmt" imported and not used (Go)declared and not usedMODULE_NOT_FOUND — Error: Cannot find module 'x' (MODULE_NOT_FOUND) (Node.js)MODULE_NOT_FOUNDnot a constructor — TypeError: x is not a constructor (JavaScript)not a constructorReferenceError — ReferenceError: x is not defined (JavaScript)ReferenceErrorRouter.use middleware — TypeError: Router.use() requires a middleware function but got a Object (Node.js)Router.use middlewareRuntime.HandlerNotFound — Runtime.HandlerNotFound: index.handler is undefined or not exported (AWS)Runtime.HandlerNotFou…TypeError…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.