vitest-dev/vitest · error · Error
MemberExpression is not supported. Please open a new bug…
Error message
MemberExpression is not supported. Please open a new bug report.
What it means
Thrown by `traversePattern` inside `automockModule` when a destructuring pattern in an `export const` declaration contains a `MemberExpression` — e.g., `export const { a: obj.prop } = x`, which assigns into a nested object property. The automock exporter cannot statically name such an export, so it refuses with a request to file a bug report.
Solutions
- Provide an explicit factory: `vi.mock(path, factory)`.
- Refactor the target module to avoid member-expression destructuring targets in exports.
- File the bug report the message requests if you need automock to support this shape.
Example fix
// before — automock cannot handle member-expression target
// mod.ts: export const { a: cfg.value } = source
vi.mock('./mod')
// after — explicit factory
vi.mock('./mod', () => ({ value: 1 })) Defensive patterns
Strategy: fallback
Validate before calling
// Member-expression destructuring targets are rare; scan for them and prefer explicit factories.
function hasMemberExpressionDestructure(ast: any): boolean {
for (const node of ast.body) {
if (node.type !== 'ExportNamedDeclaration' || !node.declaration) continue
for (const decl of node.declaration.declarations || []) {
if (containsMemberExpression(decl.id)) return true
}
}
return false
} Try / catch
try {
vi.mock('./mod')
} catch (err) {
if (err instanceof Error && err.message.includes('MemberExpression is not supported')) {
vi.mock('./mod', () => ({ /* explicit stubs */ }))
}
} Prevention
- Do not use member-expression assignment targets in export destructuring.
- Provide an explicit factory for modules with unusual export shapes.
- Refactor such exports to plain identifier assignments.
When it happens
Trigger: Automocking a module that uses a destructuring-pattern assignment target that is a member expression rather than a plain identifier or nested pattern.
Common situations: Rare in practice — most modules do not use member-expression assignment targets in `export const`. Encountered when automocking unusual or generated code that destructures into object properties.
Related errors
- AssignmentPattern is not supported. Please open a new bug…
- automocking files with `export *` is not supported because…
- failed to parse
- [@vitest/mocker] `createMockInstance` is not defined. This…
- Cannot automock ' ' because it failed to parse.
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/03d0bd96f83b23ad.
Report an issue: GitHub.
Appendix: source
Thrown at packages/mocker/src/node/automock.ts:123
else {
property satisfies never
}
})
}
else if (expression.type === 'RestElement') {
traversePattern(expression.argument)
}
// const [name[1], name[2]] = []
// cannot be used in export
else if (expression.type === 'AssignmentPattern') {
throw new Error(
`AssignmentPattern is not supported. Please open a new bug report.`,
)
}
// const test = thing.func()
// cannot be used in export
else if (expression.type === 'MemberExpression') {
throw new Error(
`MemberExpression is not supported. Please open a new bug report.`,
)
}
else {
expression satisfies never
}
}
if (declaration) {
if (declaration.type === 'FunctionDeclaration') {
allSpecifiers.push({ name: declaration.id.name })
}
else if (declaration.type === 'VariableDeclaration') {
declaration.declarations.forEach((declaration) => {
traversePattern(declaration.id)
})
}
else if (declaration.type === 'ClassDeclaration') {View on GitHub (pinned to 1fa9837ec2)