{"id":"03d0bd96f83b23ad","repo":"vitest-dev/vitest","slug":"memberexpression-is-not-supported-please-open-a-n","errorCode":null,"errorMessage":"MemberExpression is not supported. Please open a new bug report.","messagePattern":"MemberExpression is not supported\\. Please open a new bug report\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mocker/src/node/automock.ts","lineNumber":123,"sourceCode":"            else {\n              property satisfies never\n            }\n          })\n        }\n        else if (expression.type === 'RestElement') {\n          traversePattern(expression.argument)\n        }\n        // const [name[1], name[2]] = []\n        // cannot be used in export\n        else if (expression.type === 'AssignmentPattern') {\n          throw new Error(\n            `AssignmentPattern is not supported. Please open a new bug report.`,\n          )\n        }\n        // const test = thing.func()\n        // cannot be used in export\n        else if (expression.type === 'MemberExpression') {\n          throw new Error(\n            `MemberExpression is not supported. Please open a new bug report.`,\n          )\n        }\n        else {\n          expression satisfies never\n        }\n      }\n\n      if (declaration) {\n        if (declaration.type === 'FunctionDeclaration') {\n          allSpecifiers.push({ name: declaration.id.name })\n        }\n        else if (declaration.type === 'VariableDeclaration') {\n          declaration.declarations.forEach((declaration) => {\n            traversePattern(declaration.id)\n          })\n        }\n        else if (declaration.type === 'ClassDeclaration') {","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/mocker/src/node/automock.ts#L105-L141","documentation":"Thrown at packages/mocker/src/node/automock.ts:122-125 by traversePattern when traversing an export destructuring pattern encounters a MemberExpression. Member expressions in destructuring (e.g. `{ [obj.key]: value }` or computed member access in the pattern) cannot be statically analyzed into named exports, so the automocker refuses them.","triggerScenarios":"Automocking (no factory) a module containing an export destructuring pattern with a member expression, e.g. `export const { [keys.main]: primary } = source`.","commonSituations":"Automocking a module with computed/dynamic destructuring keys; refactor introducing a member expression in an exported destructure.","solutions":["Provide an explicit vi.mock factory to bypass automock parsing.","Refactor the target module to use static export names instead of computed destructuring.","Mock individual named exports rather than the whole module."],"exampleFix":"// target module (causes error when automocked):\n// export const { [config.key]: handler } = handlers\n\n// fix in the test: provide a factory\nvi.mock('./handlers', () => ({ handler: vi.fn() }))","handlingStrategy":"validation","validationCode":"// Detect member expressions in export destructuring of the target before automocking.\nimport { readFileSync } from 'node:fs'\nfunction hasMemberExpressionInExport(file: string): boolean {\n  // crude heuristic: computed/member key in exported destructure\n  return /export\\s+const\\s*\\{\\s*\\[[^\\]]+\\]/.test(readFileSync(file, 'utf-8'))\n}\n\nif (hasMemberExpressionInExport('./handlers.ts')) {\n  vi.mock('./handlers.ts', () => ({ handler: vi.fn() }))\n} else {\n  vi.mock('./handlers.ts')\n}","typeGuard":null,"tryCatchPattern":"try {\n  vi.mock('./handlers.ts')\n} catch (e) {\n  if (e instanceof Error && /MemberExpression is not supported/.test(e.message)) {\n    vi.mock('./handlers.ts', () => ({ handler: vi.fn() }))\n  } else { throw e }\n}","preventionTips":["Avoid computed/member keys in exported destructuring of modules you automock.","Provide explicit vi.mock factories for modules using dynamic destructuring.","Mock only the specific named exports you need."],"tags":["automock","ast","destructuring","member-expression"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}