{"record":{"id":"82ea749a308d8ace","repo":"vitest-dev/vitest","slug":"invalid-globalsetup-file-file-must-export-setu","errorCode":null,"errorMessage":"invalid globalSetup file ${file}. Must export setup, teardown or have a default export","messagePattern":"invalid globalSetup file (.+?)\\. Must export setup, teardown or have a default export","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/globalSetup.ts","lineNumber":47,"sourceCode":"        `invalid export in globalSetup file ${file}: ${exp} must be a function`,\n      )\n    }\n  }\n  if (m.default) {\n    return {\n      file,\n      setup: m.default,\n    }\n  }\n  else if (m.setup || m.teardown) {\n    return {\n      file,\n      setup: m.setup,\n      teardown: m.teardown,\n    }\n  }\n  else {\n    throw new Error(\n      `invalid globalSetup file ${file}. Must export setup, teardown or have a default export`,\n    )\n  }\n}\n","sourceCodeStart":29,"sourceCodeEnd":52,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/globalSetup.ts#L29-L52","documentation":"After validating types, if a globalSetup file has no default, no setup, and no teardown export, it is invalid. Every globalSetup file must provide at least one of these so Vitest has something to run. The file path is included to identify which entry in the globalSetup array failed.","triggerScenarios":"A globalSetup file that exports nothing relevant, or only unrelated helpers/constants. The path is loaded via runner.import but yields no setup/teardown/default.","commonSituations":"Empty scaffold file; importing a non-globalSetup module by mistake in the globalSetup array; a refactor that removed the exports; wrong path in config.","solutions":["Add `export default function() {}` or `export function setup() {}` / `export function teardown() {}`.","Verify the file path in the globalSetup array points to the intended setup module.","Remove the file from the globalSetup array if it isn't actually a global setup."],"exampleFix":"// before - empty setup file referenced in globalSetup\n// ./globalSetup.ts\nexport const x = 1\n\n// after\n// ./globalSetup.ts\nexport function setup() {\n  globalThis.__DB__ = connect()\n}\nexport function teardown() {\n  globalThis.__DB__.close()\n}","handlingStrategy":"validation","validationCode":"function hasGlobalSetupExport(mod) {\n  return typeof mod.default === 'function'\n    || typeof mod.setup === 'function'\n    || typeof mod.teardown === 'function'\n}\n// after importing the candidate file: if (!hasGlobalSetupExport(m)) skip / fail fast","typeGuard":"function isGlobalSetupModule(mod): mod is { default?: Function, setup?: Function, teardown?: Function } {\n  return typeof mod.default === 'function' || typeof mod.setup === 'function' || typeof mod.teardown === 'function'\n}","tryCatchPattern":null,"preventionTips":["Scaffold new globalSetup files with at least one of default/setup/teardown.","Double-check the file path in the globalSetup array.","Remove entries from the array when the file is no longer a setup module."],"tags":["global-setup","exports","missing-export"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}