medusajs/medusa · error · MedusaError
The email is not valid
Error message
The email is not valid
What it means
validateEmail uses the isEmail check (validator-style) and throws MedusaError INVALID_DATA when the string is not a syntactically valid email. Used in order/customer update flows and workflows.
Source
Thrown at packages/core/utils/src/common/is-email.ts:23
/**
* Check whether provided string is an email.
* @param email - string to check
*/
function isEmail(email: string) {
return email.toLowerCase().match(EMAIL_REGEX)
}
/**
* Used to validate user email.
* @param {string} email - email to validate
* @return {string} the validated email
*/
export function validateEmail(email: string): string {
const validatedEmail = isEmail(email)
if (!validatedEmail) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"The email is not valid"
)
}
return email.toLowerCase()
}
View on GitHub (pinned to 5e06e544a2)
Solutions
- Validate email format on the client/edge before calling the API
- Trim input and check for empty string before submitting
- Use zod/validator in your route or subscriber before invoking workflows
Example fix
// before
await sdk.store.updateCustomer({ email: input })
// after
const email = z.string().email().parse(input)
await sdk.store.updateCustomer({ email }) Defensive patterns
Strategy: validation
Validate before calling
import { isEmail } from "@medusajs/framework/utils"
if (!email || !isEmail(email.trim())) throw new Error('invalid email') Type guard
import { isEmail } from '@medusajs/framework/utils'
const isValidEmail = (v: unknown): v is string => typeof v === 'string' && isEmail(v.trim()) Try / catch
try { await workflow.run({ input }) } catch (e) { if (e.type === 'invalid_data' && /email/.test(e.message)) return res.status(400).json({ message: 'Invalid email' }); throw e } Prevention
- Validate email format client-side on all forms
- Trim input before submission
When it happens
Trigger: Calling an API or workflow with `email: "foo"`, undefined coerced to string, or emails with spaces/invalid characters; e.g. POST /store/customers/me with a bad email.
Common situations: Missing client-side validation on checkout forms, whitespace in input, test fixtures with placeholder emails like "test".
Related errors
- Email is required to create a customer
- Currency code needs to be a string
- --paths must be a directory - ${additionalPath}
- --base must be a file - ${baseFile}
- insufficient_inventory
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/a825bd3c5fbeec1b.
Report an issue: GitHub.