medusajs/medusa · error · MedusaError

NOT_FOUND

NOT_FOUND

Error message

Product variant with id: ${req.params.id} was not found

What it means

Thrown by GET /store/product-variants/:id when the variant lookup returns no variant for the given id. The variant may not exist, be deleted, or belong to a product not available in the store. Returns 404 NOT_FOUND.

Source

Thrown at packages/medusa/src/api/store/product-variants/[id]/route.ts:61

  const { data: variants = [] } = await query.graph(
    {
      entity: "variant",
      filters: {
        ...req.filterableFields,
        id: req.params.id,
      },
      fields: req.queryConfig.fields,
      context,
    },
    {
      locale: req.locale,
    }
  )

  const variant = variants[0]

  if (!variant) {
    throw new MedusaError(
      MedusaError.Types.NOT_FOUND,
      `Product variant with id: ${req.params.id} was not found`
    )
  }

  if (withInventoryQuantity) {
    await wrapVariantsWithInventoryQuantityForSalesChannel(req, [variant])
  }

  await wrapVariantsWithTaxPrices(req, [variant])

  res.json({ variant })
}

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Verify the variant via GET /store/products/:id (which includes variants) or the variants list endpoint
  2. Invalidate cached variant references (carts, wishlists, recently-viewed) when variants change
  3. Handle the 404 gracefully with a fallback to the parent product page

Example fix

// before
const { variant } = await sdk.store.productVariant.retrieve('variant_deleted')

// after
try {
  const { variant } = await sdk.store.productVariant.retrieve(id)
} catch {
  redirect(`/products/${productId}`)
}
Defensive patterns

Strategy: fallback

Validate before calling

const { variants } = await sdk.store.productVariant.list({ id: [variantId] })
if (!variants.length) redirect(`/products/${productId}`)

Try / catch

try {
  const { variant } = await sdk.store.productVariant.retrieve(id)
} catch (e: any) {
  if (e.type === 'not_found') return fallbackToProduct(productId)
  throw e
}

Prevention

When it happens

Trigger: Requesting /store/product-variants/variant_... with a nonexistent/deleted variant id, or a variant of an unpublished product; also when region/currency filters exclude it.

Common situations: Stale cart or wishlist referencing deleted variants; cached variant ids after catalog syncs; variants removed when a product's options changed.

Related errors


AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27). Data as JSON: /api/errors/42c894823f3560c0. Report an issue: GitHub.