Common Next.js errorsCannot read properties of undefined
TypeError: Cannot read properties of undefined (reading 'name') (or of null) means the code reached for a field on something that isn't there. It's the most common production crash in JavaScript apps.
Why it happens in production
- Real data has gaps your test data didn't: a product with no image, a recipe with no author.
- A lookup found nothing: a map keyed by text ids asked for a number, or a find() that missed.
- A list was empty:
items[0].name on a page past the end. - An API changed shape:
stats.period is now stats.range.
How to fix it
First find where the missing value comes from. If it's live data that can legitimately be missing, handle it visibly where it's used:
Visible fallback for data that can be missing <p>by {recipe.author?.name ?? "the team"}</p>
If it comes from a bug elsewhere (an off-by-one page count, a lookup with the wrong key type, a renamed field), fix it there instead. A guard where it crashes would only hide the bug: the page would stop crashing but still show the wrong thing.
How SteadyOn handles it
SteadyOn reads the stack trace and the files it imports, finds where the bad value comes from, and proves the fix with a test that checks the page shows the right thing, not just that it stops crashing.