{"record":{"id":"aa0c428579dd3bc9","repo":"vitest-dev/vitest","slug":"unknown-source-type-while-automocking-source","errorCode":null,"errorMessage":"unknown source type while automocking: ${source}","messagePattern":"unknown source type while automocking: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/mocker/src/node/automock.ts","lineNumber":52,"sourceCode":"\n  const m = new MagicString(code)\n\n  const allSpecifiers: { name: string; alias?: string }[] = []\n  const replacers: (() => void)[] = []\n  let importIndex = 0\n  for (const _node of ast.body) {\n    if (_node.type === 'ExportAllDeclaration') {\n      const node = _node as Positioned<ExportAllDeclaration>\n      // TODO: pass it down in the browser mode\n      if (!options.id) {\n        throw new Error(\n          `automocking files with \\`export *\\` is not supported because it cannot be easily statically analysed`,\n        )\n      }\n\n      const source = node.source.value\n      if (typeof source !== 'string') {\n        throw new TypeError(`unknown source type while automocking: ${source}`)\n      }\n\n      const moduleUrl = import.meta.resolve(source, pathToFileURL(options.id).toString())\n      const modulePath = fileURLToPath(moduleUrl)\n      const moduleContent = readFileSync(modulePath, 'utf-8')\n      const transformedCode = transformCode(moduleContent, moduleUrl)\n      const moduleFormat = resolveModuleFormat(moduleUrl, transformedCode)\n      const moduleExports = collectModuleExports(modulePath, transformedCode, moduleFormat || 'module')\n      replacers.push(() => {\n        const importNames: string[] = []\n        moduleExports.forEach((exportName) => {\n          const isReexported = allSpecifiers.some(({ name, alias }) => name === exportName || alias === exportName)\n          if (!isReexported) {\n            importNames.push(exportName)\n            allSpecifiers.push({ name: exportName })\n          }\n        })\n","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/mocker/src/node/automock.ts#L34-L70","documentation":"Thrown as a `TypeError` by `automockModule` when processing an `export *` declaration whose `node.source.value` is not a string. The AST spec requires `ExportAllDeclaration.source.value` to be a string literal; a non-string value indicates a malformed or non-standard AST produced by a buggy parser or a custom parse function.","triggerScenarios":"A custom `parse` function passed to `automockModule` returns an AST where `ExportAllDeclaration.source.value` is a node/object instead of a string; or a corrupted/instrumented source produces an unexpected AST shape. Under stock Vitest with the default acorn parser this should be unreachable.","commonSituations":"Forking Vitest or injecting a custom parser into the automock pipeline; processing source that has been pre-transformed into a non-standard AST representation.","solutions":["If using a custom parser, ensure it produces a standard ESTree-compatible `ExportAllDeclaration` with a string `source.value`.","File a Vitest bug with the source file and parser configuration if this occurs with the default parser."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// When using a custom parser, validate the AST shape before automocking.\nfunction hasStringExportStarSource(ast: any): boolean {\n  return ast.body.every((node: any) =>\n    node.type !== 'ExportAllDeclaration' || typeof node.source?.value === 'string'\n  )\n}","typeGuard":"function isExportAllWithstringLiteral(node: unknown): node is { type: 'ExportAllDeclaration'; source: { value: string } } {\n  return typeof node === 'object' && node !== null\n    && (node as any).type === 'ExportAllDeclaration'\n    && typeof (node as any).source?.value === 'string'\n}","tryCatchPattern":null,"preventionTips":["Use the default acorn parser unless you have a specific reason to swap it.","Validate custom-parser AST output against ESTree shapes before feeding it to automock."],"tags":["automock","ast","parser","internal-guard"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}