{"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":"validation","errorClass":"Error","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/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/globalSetup.ts#L29-L52","documentation":"loadGlobalSetupFile (globalSetup.ts:47) requires the module to export at least one of: default, setup, or teardown. If none is present, vitest can't know what to run for global setup and throws.","triggerScenarios":"A globalSetup file that has no default export and no setup/teardown named exports — e.g. an empty file, a file with only side effects, or one with differently-named exports.","commonSituations":"Forgetting to add a setup function; pointing globalSetup at the wrong file; file that only re-exports helpers.","solutions":["Add export default function setup() { ... } (or named setup/teardown) to the file.","Verify the path configured in test.globalSetup points at the intended file.","If you only need teardown, export an empty setup and a real teardown."],"exampleFix":"// before (globalSetup file)\nexport const utils = { ... } // no setup/teardown/default\n\n// after\nexport default function setup() { /* init */ }","handlingStrategy":"validation","validationCode":"const mod = await runner.import(file)\nif (typeof mod.default !== 'function' && typeof mod.setup !== 'function' && typeof mod.teardown !== 'function') {\n  throw new Error(`globalSetup file ${file} must export default/setup/teardown`)\n}","typeGuard":"function hasGlobalSetupExport(mod: any): boolean {\n  return typeof mod?.default === 'function'\n    || typeof mod?.setup === 'function'\n    || typeof mod?.teardown === 'function'\n}","tryCatchPattern":null,"preventionTips":["Always export a default setup function from globalSetup files.","Double-check the test.globalSetup path resolves to the intended file.","Add a smoke test that imports each globalSetup file and asserts an export."],"tags":["globalsetup","config","validation"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}