Cannot read properties of undefined
TypeError: Cannot read properties of undefined (reading '…')
Your code read a property from something that was undefined at that moment.
What it means
The code did something.name, and something was undefined (or null, which gives the same error with a different word). The name in brackets is the property it tried to read. The value to the left of it is the one that was missing. Chrome and Node.js word it this way. Firefox says "x" is undefined, and Safari undefined is not an object.
Common causes
- The data had not arrived yet. The page rendered before a fetch finished, so the value was still undefined on the first render.
- The data has a different shape from what the code expects.
data.itemswhen the API sendsdata.results, orlist[0]on an empty list. - A misspelled name further up the chain.
user.proflie.namereadsnamefrom undefined.
Ways to fix it
- MDN's advice is to check that the value is not undefined or null before reading from it. Handle the missing case on purpose, for example with a loading state, rather than adding
?.everywhere until the error disappears: a blank screen with no error is harder to debug.
A prompt to fix it
Paste it into your AI coding tool and fill in the parts in angle brackets. It asks the tool to find the cause and show you before it changes anything.
Paste it, then fill in the <angle brackets>
I get: TypeError: Cannot read properties of undefined (reading '<property>')
<paste the first lines of the stack trace>
1. Go to the exact file and line in the stack trace and tell me which value is undefined there.
2. Trace where that value comes from and tell me why it is undefined at that moment: not loaded yet, a different shape than expected, an empty list, or a misspelled name. Show me the evidence, for example by logging the real value.
3. Fix the cause. If the value can legitimately be missing for a moment (data still loading), handle that case on purpose, for example with a loading state. Do not add ?. everywhere to hide the error.How to check it is fixed
- The error is gone from the console, and the part that crashed now shows the right data.
- Try the situation that caused it on purpose: a slow connection (the network throttling option in the browser's developer tools), an empty list, a signed-out user.
Tested prompts that help
- Hand It An Error — Our test of this prompt used exactly this error, on a made-up bookings page. Its page shows what we pasted in and what came back. Test log: Pass, ChatGPT (Pro), September 27, 2026; Pass, Claude.ai (Fable 5.1 Max), September 27, 2026.
Sources
Everything above comes from these pages. We read them on September 27, 2026; if one has changed since, it wins.