{"record":{"id":"ecc623426280a122","repo":"vitest-dev/vitest","slug":"not-called-in-the-browser","errorCode":null,"errorMessage":"Not called in the browser","messagePattern":"Not called in the browser","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser/src/client/tester/state.ts","lineNumber":33,"sourceCode":"    config,\n    projectName: config.name || '',\n    metaEnv: null as any,\n    files: [],\n    environment: {\n      name: 'browser',\n      options: null,\n    },\n    // this is populated before tests run\n    providedContext: {},\n    invalidates: [],\n  },\n  onCancel: null as any,\n  config,\n  environment: {\n    name: 'browser',\n    viteEnvironment: 'client',\n    setup() {\n      throw new Error('Not called in the browser')\n    },\n  },\n  onCleanup: fn => getBrowserState().cleanups.push(fn),\n  evaluatedModules: new EvaluatedModules(),\n  resolvingModules: new Set(),\n  moduleExecutionInfo: new Map(),\n  metaEnv: null as any,\n  rpc: null as any,\n  durations: {\n    environment: 0,\n    prepare: performance.now(),\n    fetch: 0,\n  },\n  providedContext: {},\n}\n\n// @ts-expect-error not typed global\nglobalThis.__vitest_browser__ = true","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/browser/src/client/tester/state.ts#L15-L51","documentation":"Thrown by the `setup()` method of the `environment` object on the browser-side `WorkerGlobalState`. This state object is constructed only inside the browser tester; its `environment.setup` is a stub because real environment setup happens server-side before the browser context is loaded. Calling it indicates the browser worker state leaked into a non-browser caller (e.g. imported in Node) or code incorrectly invoked `environment.setup()`.","triggerScenarios":"Code that imports the browser tester state module in Node and calls `state.environment.setup()`; a setup file executed in the wrong environment; a misuse of internal Vitest APIs that reaches this stub.","commonSituations":"Mixing Node-side and browser-side Vitest internals; a custom environment/runner that calls `environment.setup()` on the browser state object; importing `vitest/browser` internals in a Node test file.","solutions":["Do not call `environment.setup()` on the browser worker state; it is set up by the runner infrastructure.","Ensure setup files and custom environments run in the correct environment (Node vs `browser`).","If this surfaces unexpectedly, it is likely a Vitest internal bug — open an issue with a reproduction."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// do not call state.environment.setup(); ensure you are not in Node when using browser state\nif (typeof window === 'undefined') {\n  throw new Error('Browser worker state is only valid in the browser tester')\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not call `environment.setup()` on the browser worker state.","Keep Node-side and browser-side Vitest internals separate.","Run setup files in the environment they target."],"tags":["internal","browser","environment","worker-state"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}