You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeError: undefined is not a function
TypeError: myFunction is not a function
TypeError: X.Y is not a function
Common Causes
Wrong import — function not exported, or wrong named vs default import
Calling before declaration — using a const function before it's defined
Typo in function name — arrary.push() instead of array.push()
Method applied to wrong type — calling .map() on an object instead of array
Detailed Solution
Solution 1: Check Your Imports
// ❌ Function is exported as named, but imported as default// utils.jsexportfunctionformatDate(date){ ... }// named export// app.jsimportformatDatefrom'./utils';// ❌ wrong (default import)import{formatDate}from'./utils';// correct (named import)// ───────────────────────────────// ❌ Importing from wrong fileimport{useState}from'react-dom';// ❌ wrongimport{useState}from'react';// correct
Solution 2: Variable Initialization Timing
// ❌ Arrow function with const cannot be hoistedrunApp();// ❌ ReferenceError — cannot call before initializationconstrunApp=()=>console.log('Running!');// Function declarations ARE hoistedrunApp();// Works!functionrunApp(){console.log('Running!');}
Solution 3: Type Mismatch
// ❌ Object doesn't have .map()constuserObj={name: 'Alice',age: 25};userObj.map(u=>u.name);// ❌ TypeError// Check type firstconstusers=Array.isArray(userObj) ? userObj : [userObj];users.map(u=>u.name);// // ❌ Calling method on null/undefinedconsthandler=null;handler.onClick();// ❌ TypeError// Check before callinghandler?.onClick?.();
Prevention
Use TypeScript for compile-time type checking
Run console.log(typeof myFunction) to debug the type of a variable