node
type_error
ai_generated
true
TypeError: Cannot read properties of undefined (reading 'property')
ID: node/typeerror-cannot-read-undefined
88%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 20 | active | — | — | — |
Root Cause
Accessing property on undefined/null. The #1 JavaScript runtime error worldwide.
genericWorkarounds
-
92% success Trace where the variable becomes undefined — check async timing, missing return, wrong key name
// Add console.log before the failing line: console.log('obj is:', typeof obj, obj); // Common causes: forgot await, wrong destructuring key, API returned nullSources: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_access_property
-
85% success Use nullish coalescing (??) with explicit defaults at the source, not at every usage
const value = response?.data ?? defaultValue;
Sources: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing
Dead Ends
Common approaches that don't work:
-
Add optional chaining (?.) everywhere
60% fail
Masks bugs — undefined propagates silently through the chain
-
Default to empty object with || {}
55% fail
Fails for falsy values (0, '', false)
Error Chain
Frequently confused with: