medusajs/medusa · error · MedusaError
Countries with codes: "${missingCountries.join(", ")}" do no
Error message
Countries with codes: "${missingCountries.join(", ")}" do not exist What it means
Thrown by the region module's validateCountries when one or more requested country codes do not exist in the installed country data. The module compares the input codes against countries in the DB (arrayDifference) and reports the exact missing codes with INVALID_DATA.
Source
Thrown at packages/modules/region/src/services/region-module.ts:359
)}" are already assigned to a region`
)
}
const countriesInDb = await this.countryService_.list(
{ iso_2: uniqueCountries },
{ select: ["iso_2", "region_id"] },
sharedContext
)
const countryCodesInDb = countriesInDb.map((c) => c.iso_2.toLowerCase())
// Countries missing in the database
if (countriesInDb.length !== uniqueCountries.length) {
const missingCountries = arrayDifference(
uniqueCountries,
countryCodesInDb
)
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Countries with codes: "${missingCountries.join(", ")}" do not exist`
)
}
// Countries that already have a region already assigned to them
// @ts-ignore
const countriesWithRegion = countriesInDb.filter((c) => !!c.region_id)
if (countriesWithRegion.length) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Countries with codes: "${countriesWithRegion
.map((c) => c.iso_2)
.join(", ")}" are already assigned to a region`
)
}
return countriesInDbView on GitHub (pinned to 5e06e544a2)
Solutions
- Check the missing codes in the message and correct them to valid ISO 3166-1 alpha-2 codes
- Ensure codes are lowercase ('us', 'dk') as expected by the region module's normalization
- If a legitimately supported country is missing, verify your Medusa version/country data is up to date
Example fix
// before
await regionService.createRegions([{ name: "NA", countries: ["usa", "can"] }])
// after
await regionService.createRegions([{ name: "NA", countries: ["us", "ca"] }]) Defensive patterns
Strategy: validation
Validate before calling
const VALID_ISO2 = /^[a-z]{2}$/ // region module uses lowercase alpha-2
function validateCountryCodes(codes: string[]) {
const invalid = codes.filter((c) => !VALID_ISO2.test(c))
if (invalid.length) throw new Error(`Invalid country codes: ${invalid.join(", ")}`)
} Type guard
function isValidIso2(code: string): boolean {
return /^[a-z]{2}$/.test(code)
} Try / catch
try {
await regionModule.createRegions(payload)
} catch (e) {
if (e instanceof MedusaError && /do not exist/.test(e.message)) {
// strip the listed codes and retry with only valid ones
} else throw e
} Prevention
- Use ISO 3166-1 alpha-2 codes in lowercase
- Validate codes against a country list constant at the edge (API/form)
- Keep country data up to date with your Medusa version
When it happens
Trigger: Calling createRegions/updateRegions with invalid or unsupported ISO 2 codes, e.g. 'zz', 'usa' (3-letter), or lowercase/non-canonical casing not normalized upstream.
Common situations: Passing ISO 3166-1 alpha-3 codes instead of alpha-2, typos in seed files, codes for countries not present in the loaded country data, or casing issues ('US' vs 'us') depending on normalization.
Related errors
- Countries with codes: "${getDuplicates(countries).join(", ")
- Countries with codes: "${countriesWithRegion.map((c) => c.is
- Country with code ${shippingAddress.country_code} is not wit
- NOT_ALLOWED
- --paths must be a directory - ${additionalPath}
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/3c90e1b25b08d409.
Report an issue: GitHub.