{"record":{"id":"aefbb1e1ea68cfe4","repo":"vitest-dev/vitest","slug":"snapshot-environment-module-must-have-a-default-ex","errorCode":null,"errorMessage":"Snapshot environment module must have a default export object with a shape of `SnapshotEnvironment`","messagePattern":"Snapshot environment module must have a default export object with a shape of `SnapshotEnvironment`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/integrations/snapshot/environments/resolveSnapshotEnvironment.ts","lineNumber":16,"sourceCode":"import type { SnapshotEnvironment } from '@vitest/snapshot/environment'\nimport type { SerializedConfig } from '../../../runtime/config'\nimport type { TestModuleRunner } from '../../../runtime/moduleRunner/testModuleRunner'\n\nexport async function resolveSnapshotEnvironment(\n  config: SerializedConfig,\n  moduleRunner: TestModuleRunner,\n): Promise<SnapshotEnvironment> {\n  if (!config.snapshotEnvironment) {\n    const { VitestNodeSnapshotEnvironment } = await import('./node')\n    return new VitestNodeSnapshotEnvironment()\n  }\n\n  const mod = await moduleRunner.import(config.snapshotEnvironment)\n  if (typeof mod.default !== 'object' || !mod.default) {\n    throw new Error(\n      'Snapshot environment module must have a default export object with a shape of `SnapshotEnvironment`',\n    )\n  }\n  return mod.default\n}\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/integrations/snapshot/environments/resolveSnapshotEnvironment.ts#L1-L22","documentation":"Thrown by `resolveSnapshotEnvironment` when the module pointed to by `config.snapshotEnvironment` was successfully imported but its `default` export is not a non-null object. Vitest expects `mod.default` to be an object implementing the `SnapshotEnvironment` interface (`getVersion`, `getHeader`, `resolvePath`, `resolveRawPath`, `saveSnapshotFile`, `readSnapshotFile`, `removeSnapshotFile`, optional `processStackTrace`). A missing/`null`/non-object default is treated as a configuration error.","triggerScenarios":"Pointing `test.snapshotEnvironment` to a module that has no default export, exports a function as default (instead of an object), exports the class instance under a named export, or exports `null`/`undefined` as default.","commonSituations":"Writing a custom snapshot environment and forgetting `export default`; exporting the class but not instantiating it; named-only exports; bundler interop producing `{ default: undefined }`; pointing the path at a file that re-exports from another module incorrectly.","solutions":["Ensure the module has `export default { getVersion() {...}, getHeader() {...}, resolvePath, resolveRawPath, saveSnapshotFile, readSnapshotFile, removeSnapshotFile }`.","If exporting a class, instantiate it: `export default new MySnapshotEnvironment()`.","Verify the resolved path matches the file you edited (check `test.snapshotEnvironment` value and the import map)."],"exampleFix":"// before\nexport class MyEnv { /* methods */ }\n\n// after\nexport class MyEnv { /* methods */ }\nexport default new MyEnv()","handlingStrategy":"validation","validationCode":"// after importing the candidate module\nconst mod = await import(config.snapshotEnvironment)\nif (typeof mod.default !== 'object' || !mod.default) {\n  throw new Error('snapshotEnvironment module needs a conforming default export')\n}\nconst required = ['getVersion','getHeader','resolvePath','resolveRawPath','saveSnapshotFile','readSnapshotFile','removeSnapshotFile']\nfor (const k of required) if (typeof mod.default[k] !== 'function') throw new Error(`missing ${k}`)","typeGuard":"function isSnapshotEnvironment(v): boolean {\n  return !!v && typeof v === 'object'\n    && ['getVersion','getHeader','resolvePath','resolveRawPath','saveSnapshotFile','readSnapshotFile','removeSnapshotFile']\n      .every(k => typeof v[k] === 'function')\n}","tryCatchPattern":null,"preventionTips":["Always export default an object implementing all SnapshotEnvironment methods.","If exporting a class, instantiate it in the default export.","Validate the default export shape with a unit test against the required method list."],"tags":["snapshot","snapshot-environment","config","default-export"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}