{"record":{"id":"46eeb94265b2c432","repo":"jestjs/jest","slug":"jsdom-did-not-return-a-window-object","errorCode":null,"errorMessage":"JSDOM did not return a Window object","messagePattern":"JSDOM did not return a Window object","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/jest-environment-jsdom-abstract/src/index.ts","lineNumber":98,"sourceCode":"        : '<!DOCTYPE html>',\n      {\n        pretendToBeVisual: true,\n        resources:\n          typeof projectConfig.testEnvironmentOptions.userAgent === 'string'\n            ? new ResourceLoader({\n                userAgent: projectConfig.testEnvironmentOptions.userAgent,\n              })\n            : undefined,\n        runScripts: 'dangerously',\n        url: 'http://localhost/',\n        virtualConsole,\n        ...projectConfig.testEnvironmentOptions,\n      },\n    );\n    const global = (this.global = this.dom.window as unknown as Win);\n\n    if (global == null) {\n      throw new Error('JSDOM did not return a Window object');\n    }\n\n    // TODO: remove at some point - for \"universal\" code (code should use `globalThis`)\n    global.global = global;\n\n    // Node's error-message stack size is limited at 10, but it's pretty useful\n    // to see more than that when a test fails.\n    this.global.Error.stackTraceLimit = 100;\n    installCommonGlobals(global, projectConfig.globals);\n\n    // TODO: remove this ASAP, but it currently causes tests to run really slow\n    global.Buffer = Buffer;\n\n    // Report uncaught errors.\n    this.errorEventListener = event => {\n      if (userErrorListenerCount === 0 && event.error != null) {\n        process.emit('uncaughtException', event.error);\n      }","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-environment-jsdom-abstract/src/index.ts#L80-L116","documentation":"Thrown after `new JSDOM(...)` when `this.dom.window` is null/undefined. JSDOM is expected to return a Window object; if it does not, the environment cannot proceed. This is a defensive check (`global == null`) after JSDOM construction.","triggerScenarios":"JSDOM constructor returns an object whose `.window` is null — this can happen with a broken JSDOM build, a jsdom constructor called with invalid options that silently produces no window, or a jsdom module that is a mock/stub.","commonSituations":"A test setup that mocks or stubs `jsdom` globally. A corrupted or partial jsdom installation. Using an extremely old jsdom version that has different constructor behavior. Memory exhaustion causing JSDOM to fail silently.","solutions":["Reinstall `jsdom` and `jest-environment-jsdom` to rule out a corrupted install.","Check that no test setup or mock is overriding the `jsdom` module.","Verify Node.js version meets the minimum requirement for your jsdom version.","Try a minimal `new (require('jsdom').JSDOM)('<html></html>')` in a standalone script to isolate."],"exampleFix":"// diagnosis script\nconst { JSDOM } = require('jsdom');\nconst dom = new JSDOM('<!DOCTYPE html>');\nconsole.log(typeof dom.window); // should print 'object'","handlingStrategy":"validation","validationCode":"// Smoke-test JSDOM window creation\nfunction smokeTestJsdom() {\n  const { JSDOM } = require('jsdom');\n  const dom = new JSDOM('<!DOCTYPE html>');\n  if (dom.window == null) {\n    throw new Error('JSDOM failed to produce a window — check jsdom installation');\n  }\n}","typeGuard":"function hasJsdomWindow(dom: unknown): dom is { window: object } {\n  return dom != null && typeof (dom as any).window === 'object' && (dom as any).window !== null;\n}","tryCatchPattern":null,"preventionTips":["Run a JSDOM smoke test after installing or upgrading jsdom.","Ensure no global mocks override the jsdom module.","Keep Node.js version within the range supported by your jsdom version."],"tags":["jest-environment-jsdom","jsdom","runtime-error","environment"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}