Skip to content
LavaFlowPreview

Project:shop

Docs (opens in a new tab)

TypeError: Cannot read properties of undefined (reading <str>)

Diagnosis

Checkout reads the cart total before the cart loads.

Root cause

getCart in src/cart.js returns undefined for an expired session, and handler in src/checkout.js reads cart.total without a check.

Evidence

Confidence: High

Files

  • src/checkout.js

Suggested fix

Return 404 from handler when getCart returns undefined.

Return 404 when the session's cart is gone

src/checkout.js
Removed:   const total = cart.total;Added:   if (!cart) return new Response("Cart not found", { status: 404 });Added:   const total = cart.total;