medusajs/medusa · error · MedusaError
Rule value must be an array for in/nin operators
Error message
Rule value must be an array for in/nin operators
What it means
For the in and nin operators the rule value must be an array. Passing a scalar (string/number/bool) throws INVALID_DATA.
Source
Thrown at packages/modules/fulfillment/src/utils/utils.ts:131
if (!isString(rule.operator)) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Rule operator must be a string"
)
}
if (!availableOperators.includes(rule.operator as RuleOperator)) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Rule operator ${
rule.operator
} is not supported. Must be one of ${availableOperators.join(", ")}`
)
}
if (rule.operator === RuleOperator.IN || rule.operator === RuleOperator.NIN) {
if (!Array.isArray(rule.value)) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Rule value must be an array for in/nin operators"
)
}
} else {
if (Array.isArray(rule.value) || isObject(rule.value)) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Rule value must be a string, bool, number value for the selected operator ${rule.operator}`
)
}
}
return true
}
export function normalizeRulesValue<T extends Partial<Rule>>(rules: T[]): void {
rules.forEach((rule: any) => {View on GitHub (pinned to 5e06e544a2)
Solutions
- Wrap the value in an array for in/nin rules
- Use eq/neq for single scalar comparisons
Example fix
// before
rules: [{ attribute: 'iso', operator: 'in', value: 'dk' }]
// after
rules: [{ attribute: 'iso', operator: 'in', value: ['dk', 'se'] }] Defensive patterns
Strategy: validation
Validate before calling
if ((rule.operator === 'in' || rule.operator === 'nin') && !Array.isArray(rule.value)) rule.value = [rule.value]
Type guard
const isArrayValueForInRule = (r: any): boolean => !(r.operator === 'in' || r.operator === 'nin') || Array.isArray(r.value)
Prevention
- Auto-wrap scalars for in/nin in your rule builder
- Prefer eq for single-value comparisons
When it happens
Trigger: rules: [{ attribute: 'iso', operator: 'in', value: 'dk' }] instead of value: ['dk'].
Common situations: Copying a single-value eq rule and changing only the operator; form inputs sending a single string where the API expects a list.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Rule must have an attribute, an operator and a value
- Rule operator ${rule.operator} is not supported. Must be one
- Rule value must be a string, bool, number value for the sele
- Invalid rule attribute - ${ruleAttributeId}
- The following shipping options do not exist: ${Array.from(mi
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/64ad46d0f5912058.
Report an issue: GitHub.