Meituan-Dianping/mpvue · error
Invalid v-for expression: ${exp}
Error message
Invalid v-for expression: ${exp} What it means
The v-for attribute value could not be parsed by forAliasRE, which expects the form 'alias in expression' (also 'of'). The compiler warns with the raw expression and skips generating the list render, so the element will not loop as intended.
Source
Thrown at packages/weex-template-compiler/build.js:1647
}
el.key = exp;
}
}
function processRef (el) {
var ref = getBindingAttr(el, 'ref');
if (ref) {
el.ref = ref;
el.refInFor = checkInFor(el);
}
}
function processFor (el) {
var exp;
if ((exp = getAndRemoveAttr(el, 'v-for'))) {
var inMatch = exp.match(forAliasRE);
if (!inMatch) {
process.env.NODE_ENV !== 'production' && warn(
("Invalid v-for expression: " + exp)
);
return
}
el.for = inMatch[2].trim();
var alias = inMatch[1].trim();
var iteratorMatch = alias.match(forIteratorRE);
if (iteratorMatch) {
el.alias = iteratorMatch[1].trim();
el.iterator1 = iteratorMatch[2].trim();
if (iteratorMatch[3]) {
el.iterator2 = iteratorMatch[3].trim();
}
} else {
el.alias = alias;
}
}
}View on GitHub (pinned to 6c5d78ee04)
Solutions
- Include the 'in' (or 'of') alias clause: v-for="item in items"
- Check the expression for typos or missing parts
- If v-for is dynamic, ensure the bound value always yields a valid 'alias in expr' string
Example fix
// before
<li v-for="item">{{ item }}</li>
// after
<li v-for="item in items">{{ item }}</li> Defensive patterns
Strategy: validation
Validate before calling
function isValidVFor(exp) {
return typeof exp === 'string' && /\s(?:in|of)\s/.test(exp);
}
// check all v-for attributes in a template source
function scanVFor(template) {
const re = /v-for="([^"]*)"/g; let m, bad = [];
while ((m = re.exec(template))) if (!isValidVFor(m[1])) bad.push(m[1]);
return bad;
} Type guard
function hasValidVFor(exp) {
return typeof exp === 'string' && /\s(?:in|of)\s/.test(exp);
} Prevention
- Always write v-for="alias in iterable"
- Lint templates for v-for values lacking ' in ' or ' of '
- Avoid dynamic v-for expressions that could produce malformed strings
When it happens
Trigger: Writing v-for with a missing or malformed 'in'/'of' clause, e.g. v-for="item" or v-for="(item, index)" with no iterable expression, so exp.match(forAliasRE) returns null in dev mode.
Common situations: Typos like v-for="item inin items", forgetting the iterable after the alias, or dynamic v-for bindings that resolve to an invalid string.
Related errors
- <template> cannot be keyed. Place the key on real elements i
- tag <${tag}> has no matching end tag.
- Templates should only be responsible for mapping the state t
- v-${el.elseif ? ('else-if="' + el.elseif + '"') : 'else'} us
- text "${children[i].text.trim()}" between v-if and v-else(-i
AI-assisted analysis of Meituan-Dianping/mpvue@6c5d78ee04 (2026-09-02).
Data as JSON: /api/errors/4ddf7f9930886a4b.
Report an issue: GitHub.