Error Explainer
Paste a confusing error message or stack trace and get a plain-English explanation, plus what to check first.
New to this? Read the guide.
What it produces
Real output from this tool, not a mock-up.
What went in
- Error message or stack trace
- TypeError: Cannot read properties of undefined (reading 'map') at ProductList (webpack-internal:///./src/components/ProductList.tsx:24:31) at renderWithHooks (.../react-dom.development.js:15486:18) at mountIndeterminateComponent (.../react-dom.development.js:20103:13)
- Language or framework
- React 18 with Next.js, TypeScript, fetching from an API route
- What you were trying to do
- Rendering a list of products fetched from /api/products on page load
What it means
This is a TypeError, meaning your code tried to do something with a value that isn't the type it expected. Here specifically, something is undefined when your code calls .map() on it. Arrays have a .map() method, undefined does not, so JavaScript throws. The trace shows this happens at 'ProductList (webpack-internal:///./src/components/ProductList.tsx:24:31)', which is your own component, not a library internal. That's good news, it means the bug is in code you can actually see and edit, at line 24 column 31 of ProductList.tsx. Everything below that frame (renderWithHooks, mountIndeterminateComponent, beginWork) is just React's internal machinery calling your component, it's not where the actual mistake lives. Given you're fetching from /api/products on page load, the most common cause of this exact error is that the data hasn't arrived yet when the component first renders, and whatever variable holds your product list starts out as undefined (rather than an empty array) before the fetch resolves. Another common cause with API routes specifically: the API response shape doesn't match what the component expects, for example the route returns {products: [...]} but the component tries to .map() over the whole response object instead of response.products, or the API call failed and returned an error object with no array at all. This is a textbook 'data not loaded yet' or 'wrong data shape' bug, not a framework or React 18 quirk. The fix is almost always in how you initialize state and how you access the fetched data, both of which are on or near that line 24 in ProductList.tsx.
What to check first
- Open ProductList.tsx and look at line 24, column 31, specifically identify what variable you're calling .map() on and where it's declared or initialized (state, props, or a fetch result)
- If that variable comes from useState, check its initial value, if it's useState() or useState(undefined) with no default, change it to useState([]) so it's an empty array before data loads
- Log or inspect the actual response from /api/products (in the browser network tab or with a console.log) to confirm it returns an array directly or an object wrapping the array, and adjust the .map() call to match the real shape
- Add a guard before rendering, like checking the array exists (or has length) before calling .map(), or render a loading state until the fetch completes, so the component doesn't try to map over data that hasn't arrived
When to use it
Use this when an error message tells you something is wrong but not what to do about it. Paste the message or the whole stack trace and you get a plain explanation of what it means, plus an ordered list of what to check first.