Your AI-built app crashes with TypeError: Cannot read properties of undefined (reading 'streak') — and the code looks fine.
What it means: some variable your code expected to hold data was empty when the code ran. In AI-built apps, this is usually a timing problem: the screen renders before the data arrives, and the code tries to read the data too early.
Why it happens:
- Data loads asynchronously, but the UI renders immediately
- An API returned an empty or differently-shaped response than the AI assumed
- A prop or state value was never set on this code path
The fix:
- Find the line in the error — the first file/line in the stack that's yours.
- Add a guard: show a loading state until the data exists —
if (!habit) return <p>Loading…</p>. - Log the actual API response once. AI-written code often assumes a shape the API doesn't return.
Paste this into your AI:
"I'm getting 'Cannot read properties of undefined'. The data probably hasn't loaded when this renders. Add a loading guard, and show me what shape of data this component actually receives."
This is Debug Clinic pattern #4 in Last20 Academy — the five errors every vibe coder hits, each with the fix and the exact prompt to paste. Try it free: https://last20.appliedefficiencyai.com/kit
Top comments (0)