Common causes
- A function returned undefined instead of the expected object
- An array index is out of bounds — accessing arr[5] when the array has 3 items
- An async operation hasn't completed yet and the result is still undefined
- A typo in a variable or property name
How to fix it
- Add a null check before accessing the property: if (obj && obj.property)
- Use optional chaining to safely access nested properties: obj?.property?.nested
- Log the variable before the failing line to see its actual value: console.log(obj)
- Check that any async data fetching has completed before accessing the result
Example
TypeError: Cannot read properties of undefined (reading 'name')
at getUserName (/home/user/app.js:15:20)
at Object.<anonymous> (/home/user/app.js:30:5)Accessing user.name when getUser() returned undefined because the user wasn't found
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
