{"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":"validation","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/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/mocker/src/node/automock.ts#L34-L70","documentation":"Thrown at packages/mocker/src/node/automock.ts:50-53 as a TypeError when an ExportAllDeclaration's source.value is not a string. AST source values are normally string literals, so a non-string source indicates a malformed or unexpected AST shape produced by the parser, which the automocker cannot resolve to a module path.","triggerScenarios":"The parser yields an ExportAllDeclaration whose source.value is not a string (e.g. a non-literal source, or a parser quirk). Then `unknown source type while automocking: ${source}` reports the actual value.","commonSituations":"Parser divergence on unusual `export *` constructs; a custom parse callback returning a non-standard AST; edge-case syntax the parser represents differently than expected.","solutions":["Provide an explicit vi.mock factory to bypass automock parsing of the offending module.","Avoid non-standard `export *` forms in the mocked module.","Report with a reproduction including the source file, as this indicates an unhandled AST shape."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  vi.mock('./oddModule.ts')\n} catch (e) {\n  if (e instanceof Error && /unknown source type while automocking/.test(e.message)) {\n    vi.mock('./oddModule.ts', () => ({}))\n  } else { throw e }\n}","preventionTips":["Provide explicit vi.mock factories for modules with non-standard `export *` forms.","Avoid parser-edge-case constructs in modules you intend to automock.","Report unusual AST shapes to Vitest with a reproduction."],"tags":["automock","ast","internal","typeerror"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}