Learn how to read stack traces, interpret common error types, and systematically debug JavaScript, TypeScript, and Node.js errors without just Googling the message.
Most developers' first instinct when they see an error is to copy the message and paste it into Google. That's fine for unfamiliar errors, but learning to read errors directly saves far more time. Every error message is a clue — if you know how to read it.
TypeError: Cannot read properties of undefined (reading 'map')
at ProductList (src/components/ProductList.tsx:24:17)
at renderWithHooks (node_modules/react-dom/cjs/react-dom.development.js:14985:18)
at mountIndeterminateComponent (node_modules/react-dom/cjs/react-dom.development.js:17811:13)
at beginWork (node_modules/react-dom/cjs/react-dom.development.js:19049:16)
Reading the stack trace:
TypeError, trying to call .map on undefinedProductList.tsx:24:17 (file, line 24, column 17)node_modules frames for now; they're framework internalsWhat this error means: Something expected to be an array is actually undefined. Go to line 24 of ProductList.tsx.
const user = undefined;
user.name; // TypeError
Cause: You're accessing a property on undefined or null.
Fix: Add a null check or use optional chaining: user?.name
console.log(myVariable); // ReferenceError
Cause: Variable doesn't exist in scope — typo, wrong scope, missing import. Fix: Check spelling. Check that you've imported or declared it.
SyntaxError: Unexpected token '}'
Cause: Parser can't understand your code — usually a missing bracket, comma, or quote. Fix: Check the line indicated AND the lines above it (often the real error is one line up).
Error: ENOENT: no such file or directory, open './config.json'
Cause: File path doesn't exist.
Fix: Check the path, check your working directory (process.cwd()).
Error: connect ECONNREFUSED 127.0.0.1:5432
Cause: Tried to connect to a server that isn't running. Fix: Start the service (database, Redis, etc.) and verify the port.
The full error message, file name, and line number tell you almost everything.
Ignore node_modules frames. Go to the first frame that points to your file.
The error is often caused by the line above the one that crashes (null returned from an async function, wrong import, etc.)
console.log('products:', products, typeof products);
// or
debugger; // pauses in browser/Node debugger
Comment out code until the error disappears. The last thing you commented out is the cause.
git diff HEAD~1 — if it worked before your last change, the bug is in that diff.
TypeScript found a type mismatch. Read carefully: it tells you what type you have and what type is expected.
// Error: Type 'string | null' is not assignable to type 'string'
function greet(name: string) {}
const input = form.value; // type: string | null
greet(input); // error — could be null
// Fix
if (input !== null) greet(input);
// or
greet(input ?? '');
You're accessing a property that isn't in the type definition. Check spelling, check that you're using the right variable, or update the type.
console.trace() — prints full stack trace at any pointdebugger keyword — pauses execution in browser dev toolsDebugging is a skill that compounds. Every time you read an error message carefully instead of copy-pasting it to Google, you build pattern recognition. After six months of deliberate practice, most errors take seconds instead of minutes to diagnose.