medusajs/medusa · error · MedusaError
No regions found
Error message
No regions found
What it means
prepareCartToCreateStep resolves the cart's region (from input region_id or fallback). If no region can be resolved, cart creation is aborted with NOT_FOUND because a cart cannot exist without a region and its currency.
Source
Thrown at packages/core/core-flows/src/cart/workflows/create-carts.ts:85
customer?: { id: string; email: string } | null
}
/**
* The sales channel the cart belongs to.
*/
salesChannel: { id: string } | null
}
/**
* This step prepares the data used to create a cart, resolving the cart's
* currency, region, customer, sales channel, and a default shipping address
* when the region has a single country. It throws an error if no region is
* provided.
*/
export const prepareCartToCreateStep = createStep(
"prepare-cart-to-create",
async (data: PrepareCartToCreateStepInput) => {
if (!data.region) {
throw new MedusaError(MedusaError.Types.NOT_FOUND, "No regions found")
}
const data_ = {
...data.input,
currency_code: data.input.currency_code ?? data.region.currency_code,
region_id: data.region.id,
}
if (data.customerData.customer?.id) {
data_.customer_id = data.customerData.customer.id
data_.email = data.input?.email ?? data.customerData.customer.email
}
data_.sales_channel_id = data.salesChannel!.id
// If there is only one country in the region, we prepare a shipping address with that country's code.
if (!data.input.shipping_address && data.region.countries.length === 1) {
data_.shipping_address = {View on GitHub (pinned to 5e06e544a2)
Solutions
- Create at least one region via the Admin API (POST /admin/regions) with countries and currency
- Pass region_id explicitly when creating carts from the storefront
- If the region should exist, verify its id and that it was not soft-deleted
Example fix
// before
const { result } = await createCartWorkflow(container).run({ input: { email: 'a@b.com' } })
// after
await createRegionIfMissing()
const { result } = await createCartWorkflow(container).run({ input: { email: 'a@b.com', region_id: process.env.STOREFRONT_REGION_ID } }) Defensive patterns
Strategy: validation
Validate before calling
const { data: regions } = await query.graph({ entity: 'region', fields: ['id', 'currency_code'], filters: {} })
if (!regions.length) throw new Error('No regions configured — create one via Admin before creating carts')
const region_id = input.region_id ?? regions[0].id Type guard
const hasUsableRegion = (regions: RegionDTO[]) => regions.length > 0
Prevention
- Make region creation part of store bootstrap scripts
- Store a canonical region_id in storefront env config
- Alert when region count drops to zero (accidental deletion)
When it happens
Trigger: Calling createCartWorkflow without a region_id when the store has no regions (or none reachable from the fallback context), or with a region_id that does not exist / belongs to a deleted region.
Common situations: Fresh Medusa store where no region has been created yet; region was deleted after launch while the storefront omits region_id; typo'd region id in storefront env/config; seeded store missing region setup.
Related errors
- invalid_data
- Variants with IDs ${priceNotFound.join(", ")} do not have a
- Country with code ${shippingAddress.country_code} is not wit
- invalid_data
- Cart ${cart.id} already has a payment collection
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/07117b18133657b8.
Report an issue: GitHub.