{"record":{"id":"07117b18133657b8","repo":"medusajs/medusa","slug":"no-regions-found","errorCode":null,"errorMessage":"No regions found","messagePattern":"No regions found","errorType":"exception","errorClass":"MedusaError","httpStatus":404,"severity":"error","filePath":"packages/core/core-flows/src/cart/workflows/create-carts.ts","lineNumber":85,"sourceCode":"    customer?: { id: string; email: string } | null\n  }\n  /**\n   * The sales channel the cart belongs to.\n   */\n  salesChannel: { id: string } | null\n}\n\n/**\n * This step prepares the data used to create a cart, resolving the cart's\n * currency, region, customer, sales channel, and a default shipping address\n * when the region has a single country. It throws an error if no region is\n * provided.\n */\nexport const prepareCartToCreateStep = createStep(\n  \"prepare-cart-to-create\",\n  async (data: PrepareCartToCreateStepInput) => {\n    if (!data.region) {\n      throw new MedusaError(MedusaError.Types.NOT_FOUND, \"No regions found\")\n    }\n\n    const data_ = {\n      ...data.input,\n      currency_code: data.input.currency_code ?? data.region.currency_code,\n      region_id: data.region.id,\n    }\n\n    if (data.customerData.customer?.id) {\n      data_.customer_id = data.customerData.customer.id\n      data_.email = data.input?.email ?? data.customerData.customer.email\n    }\n\n    data_.sales_channel_id = data.salesChannel!.id\n\n    // If there is only one country in the region, we prepare a shipping address with that country's code.\n    if (!data.input.shipping_address && data.region.countries.length === 1) {\n      data_.shipping_address = {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/core/core-flows/src/cart/workflows/create-carts.ts#L67-L103","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst { result } = await createCartWorkflow(container).run({ input: { email: 'a@b.com' } })\n\n// after\nawait createRegionIfMissing()\nconst { result } = await createCartWorkflow(container).run({ input: { email: 'a@b.com', region_id: process.env.STOREFRONT_REGION_ID } })","handlingStrategy":"validation","validationCode":"const { data: regions } = await query.graph({ entity: 'region', fields: ['id', 'currency_code'], filters: {} })\nif (!regions.length) throw new Error('No regions configured — create one via Admin before creating carts')\nconst region_id = input.region_id ?? regions[0].id","typeGuard":"const hasUsableRegion = (regions: RegionDTO[]) => regions.length > 0","tryCatchPattern":null,"preventionTips":["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)"],"tags":["cart","region","setup","store-setup"],"backgroundTag":"no-regions-configured","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}