Node "Cannot read properties of undefined (reading X)" in CI - Fix the Null Access
This TypeError means you read a property off undefined or null. The crash names the property, and the value one level up is the real culprit.
What this error means
A node process throws TypeError: Cannot read properties of undefined (reading "<prop>"). The object you indexed into was undefined at that point in CI.
node
TypeError: Cannot read properties of undefined (reading 'name')
at formatUser (/home/runner/work/app/app/src/user.js:8:20)
at Object.<anonymous> (/home/runner/work/app/app/src/index.js:3:1)Common causes
An upstream lookup returned undefined
A find, parse, or API call returned no value in the CI data set, and the next line indexed into it.
A config or env value missing in CI
An object built from environment data is partial in CI, so a nested property is absent.
How to fix it
Guard with optional chaining and defaults
- Use optional chaining so the access does not throw on undefined.
- Provide a default for the missing branch.
JavaScript
const name = user?.name ?? 'unknown';Assert the value exists before using it
- Throw a descriptive error if the upstream value is missing.
- That surfaces the real cause instead of an opaque property read.
JavaScript
if (!user) throw new Error('user not found for id ' + id);How to prevent it
- Use TypeScript strict null checks and optional chaining, validate upstream lookups, and seed CI test data so objects are fully populated.
Related guides
Node "TypeError: X is not a function" in CI - Fix the Bad CallFix the Node.js "TypeError: X is not a function" in CI by correcting a bad import shape, a missing method, or…
Node "ReferenceError: X is not defined" in CI - Track Down the Missing SymbolFix the Node.js "ReferenceError: X is not defined" in CI by importing the symbol, defining the variable, or r…
Node ERR_INVALID_ARG_TYPE in CI - Pass the Right Argument TypeFix the Node.js ERR_INVALID_ARG_TYPE error in CI by passing the argument type a core API expects instead of u…