medusajs/medusa · error · MedusaError
Line item with id: ${input.item_id} was not found
Error message
Line item with id: ${input.item_id} was not found What it means
findLineItemToUpdateStep looks up the requested item_id among the cart's current line items; if absent it throws NOT_FOUND. The cart snapshot passed to the workflow and the cart's actual contents are out of sync.
Source
Thrown at packages/core/core-flows/src/cart/workflows/update-line-item-in-cart.ts:73
customer: CustomerDTO
region: RegionDTO
}
interface FindLineItemToUpdateStepInput {
cart: CartQueryDTO
input: UpdateLineItemInCartWorkflowInputDTO & AdditionalData
}
/**
* This step finds the line item to update in the cart and collects its variant
* id. It throws an error if the line item isn't found in the cart.
*/
export const findLineItemToUpdateStep = createStep(
"find-line-item-to-update",
async ({ cart, input }: FindLineItemToUpdateStepInput) => {
const item = cart.items.find((i) => i.id === input.item_id)
if (!item) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Line item with id: ${input.item_id} was not found`
)
}
const variantIds = [item.variant_id].filter(Boolean)
return new StepResponse({ item, variantIds })
}
)
interface PrepareLineItemUpdateStepInput {
input: UpdateLineItemInCartWorkflowInputDTO & AdditionalData
variants: any
item: CartQueryDTO["items"][number]
}
/**
* This step builds the update payload for a cart line item, resolving its unitView on GitHub (pinned to 5e06e544a2)
Solutions
- Refetch the cart (with items) before updating and submit an id from cart.items
- Ensure the UI sends the line item id (item.id), not variant_id or product id
- Debounce/serialize quantity update requests to avoid racing a concurrent removal
- Treat this as recoverable: prompt the user to refresh their cart
Example fix
// before
await updateLineItemInCartWorkflow(container).run({ input: { cart_id, item_id: variantId, update: { quantity: 2 } } })
// after
const { data: [cart] } = await query.graph({ entity: 'cart', filters: { id: cart_id }, fields: ['items.id'] })
const item = cart.items.find((i) => i.id === item_id)
if (!item) throw new Error('Item no longer in cart — refresh')
await updateLineItemInCartWorkflow(container).run({ input: { cart_id, item_id: item.id, update: { quantity: 2 } } }) Defensive patterns
Strategy: validation
Validate before calling
const { data: [cart] } = await query.graph({ entity: 'cart', filters: { id: cart_id }, fields: ['items.id'] })
if (!cart.items.some((i) => i.id === item_id)) {
throw new Error('Line item no longer in cart — refetch cart')
} Type guard
const isInCart = (cart: CartDTO, itemId: string): boolean => cart.items?.some((i) => i.id === itemId) ?? false
Try / catch
try {
await updateLineItemInCartWorkflow(container).run({ input })
} catch (e) {
if (e instanceof MedusaError && e.type === MedusaError.Types.NOT_FOUND && /Line item/.test(e.message)) {
// refetch cart, reconcile local state, retry or inform user
}
} Prevention
- Always send line item ids from a freshly fetched cart, not cached state
- Serialize cart mutation requests per cart (queue/debounce)
- Distinguish item.id from variant_id in your UI state model
When it happens
Trigger: Calling updateLineItemInCart with an item_id that is not in cart.items — the item was already removed, the cart was emptied, or a stale/wrong id was submitted.
Common situations: Storefront holding a stale cart in local state after another tab/request removed items; race between remove and update requests; frontend passing the product/variant id instead of the line item id.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- invalid_data
- Line item ${item.title} has no unit price
- invalid_data
- --config file must be of type .json or .yaml - ${configFileC
- invalid_data
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/2af7734181d99e91.
Report an issue: GitHub.