{"record":{"id":"9a91ce111e00584d","repo":"vitest-dev/vitest","slug":"assignmentpattern-is-not-supported-please-open-a","errorCode":null,"errorMessage":"AssignmentPattern is not supported. Please open a new bug report.","messagePattern":"AssignmentPattern 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":116,"sourceCode":"            if (property.type === 'RestElement') {\n              traversePattern(property)\n            }\n            // export const { test, test2: alias } = {}\n            else if (property.type === 'Property') {\n              traversePattern(property.value)\n            }\n            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 })","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/mocker/src/node/automock.ts#L98-L134","documentation":"Thrown by `traversePattern` inside `automockModule` when walking the destructuring pattern of an `export const` declaration and encountering an `AssignmentPattern` node — i.e., a destructuring element with a default value such as `export const [a = 1] = arr` or `export const { x = 1 } = obj`. The automock exporter does not handle default values in destructured exports, so it refuses rather than producing a silently-wrong mock.","triggerScenarios":"Automocking (`vi.mock(path)` without a factory) a module that exports via destructuring with defaults: `export const { a = defaultA } = obj` or `export const [first = 'x'] = list`.","commonSituations":"Automocking utility modules that use destructuring defaults for configuration; modules that destructure from a config object with fallbacks.","solutions":["Provide an explicit factory to `vi.mock(path, factory)` to skip automock's static export analysis.","Refactor the target module's exports to avoid default values in destructuring patterns.","File the bug report requested by the message if you want automock to support this pattern."],"exampleFix":"// before — automock chokes on the default value\n// mod.ts: export const { timeout = 3000 } = config\nvi.mock('./mod')\n// after — explicit factory\nvi.mock('./mod', () => ({ timeout: 5000 }))","handlingStrategy":"validation","validationCode":"// Scan the target module for destructured exports with defaults before automocking.\nfunction hasAssignmentPatternExport(ast: any): boolean {\n  for (const node of ast.body) {\n    if (node.type !== 'ExportNamedDeclaration' || !node.declaration) continue\n    for (const decl of node.declaration.declarations || []) {\n      if (containsAssignmentPattern(decl.id)) return true\n    }\n  }\n  return false\n}","typeGuard":null,"tryCatchPattern":"try {\n  vi.mock('./mod')\n} catch (err) {\n  if (err instanceof Error && err.message.includes('AssignmentPattern is not supported')) {\n    vi.mock('./mod', () => ({ /* explicit stubs */ }))\n  }\n}","preventionTips":["Avoid default values in destructured exports of modules you automock.","Provide explicit factories for modules that use destructuring defaults.","Refactor such exports to plain identifiers where possible."],"tags":["automock","destructuring","assignment-pattern","vi-mock"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}