References

Common Mistakes

Frequently encountered errors and their root causes.

Core Patterns

  • JavaScript/TypeScript
  • React
  • Node.js/Express
  • TypeScript-Specific

JavaScript/TypeScript

ErrorCommon Root CauseFix
Cannot read properties of undefinedVariable is undefined, accessing .propertyCheck data flow — where should this value come from?
x is not a functionWrong import, or value is not a functionCheck import statement, log typeof x
Maximum call stack size exceededInfinite recursionCheck base case, log recursion depth
Cannot find moduleWrong path, missing installCheck path relativity, run npm install
Unexpected tokenSyntax error or wrong file typeCheck for missing brackets, commas, semicolons
Assignment to constant variableReassigning constUse let if value changes, or create new variable

React

ErrorCommon Root CauseFix
”Too many re-renders”setState called during render (not in handler/effect)Move setState into useEffect or event handler
”Invalid hook call”Hook called conditionally, in loop, or outside componentFollow Rules of Hooks — top level only
”Each child should have unique key”Missing or duplicate key prop in listUse unique, stable ID (not array index)
“Cannot update unmounted component”setState after component unmountsAdd cleanup in useEffect, use AbortController
”Objects are not valid as React child”Rendering object instead of string/numberAccess specific property: {user.name} not {user}
Stale closure in useCallbackEmpty dependency array captures old valuesInclude dependencies in array
Infinite useEffect loopObject/array in dependency array (new reference each render)Memoize with useMemo or move inside effect

Node.js/Express

ErrorCommon Root CauseFix
ECONNREFUSEDTarget service not runningCheck if DB/API is up, correct port
EADDRINUSEPort already in useKill existing process or use different port
CORS errorMissing CORS headersAdd cors() middleware or set headers
”Headers already sent”Calling res.json() twiceReturn after first response
UnhandledPromiseRejectionMissing try/catch in async handlerWrap async handlers, add error middleware
ENOMEMMemory leak or large payloadProfile memory, add limits, stream large data

TypeScript-Specific

ErrorCommon Root CauseFix
Type 'X' is not assignable to type 'Y'Type mismatchCheck both types, use type assertion only if certain
Property 'x' does not exist on type 'Y'Missing property in type definitionAdd to interface or use optional chaining
Argument of type 'string' is not assignable to parameter of type '...'String literal vs string typeUse as const or literal type
No error but wrong runtime behavioras assertion overriding compilerReplace as with type guards or validation

Debugging Mindset

When You’re Stuck

  1. Take a break — Fresh eyes find bugs faster
  2. Explain the problem out loud — Rubber duck debugging
  3. Read the error message again — Slowly, word by word
  4. Check git diff — What changed since it last worked?
  5. Simplify — Remove complexity until bug disappears, then add back
  6. Search — Error message + framework name in search engine
  7. Minimal reproduction — Create smallest code that reproduces the bug

Questions to Ask Yourself

  • What do I expect to happen?
  • What actually happens?
  • What’s different between those two?
  • When did this last work? What changed since then?
  • Am I sure about my assumptions? How can I verify?