n8n error

Fix “Cannot read properties of undefined” in n8n

⚠️ Cannot read properties of undefined (reading 'country')

What this error means

Your expression walks into an object one level at a time. If any level along the path is missing for the current item, JavaScript has nothing to read the next property from and stops with this error. The word in brackets is the property it tried to read.

Common causes

  • The field is missing for some items only (one customer has no shipping address, one webhook omits a block).
  • A typo in a field name, so the parent level is undefined for every item.
  • The data is nested differently than you expect, e.g. under body for Webhook nodes ($json.body.order, not $json.order).
  • You are reading from the wrong item or node, so the object you expect isn't there.

How to fix it

  1. Open the failing node, look at its input panel and find the exact path to the value — including body for webhooks.
  2. Replace each risky dot with ?. so a missing level returns undefined instead of throwing.
  3. Add a fallback with ?? so the next node always receives a usable value.
  4. If the missing data means the item should not continue, add an IF or Filter node before the step instead of a fallback.

❌ Breaks

{{ $json.order.shipping.country }}

✅ Works

{{ $json.order?.shipping?.country ?? 'Unknown' }}

💡 Pro tip: Optional chaining hides missing data silently. If a missing field means bad data, it's often better to stop the item with an IF node and alert someone than to write 'Unknown' into your CRM.

🧪 Fix it yourself

Some orders arrive without a shipping block, and the workflow crashes on them. Make the expression return the country, or 'Unknown' when shipping is missing.

// Item 1
{ "order": { "id": 1, "shipping": { "country": "AE" } } }
// Item 2
{ "order": { "id": 2 } }
$json.order ?? 'Unknown'

⚙️ Your fix is executed against both test items — any correct solution passes.

📖 n8n ?. (optional chaining) reference →

Was this page helpful?

Practice the skill behind this fix

More n8n errors