{"id":"4619b9b480914236","repo":"jestjs/jest","slug":"unable-to-forward-jsdom-console-output-neither-s","errorCode":null,"errorMessage":"Unable to forward JSDOM console output - neither sendTo nor forwardTo methods are available","messagePattern":"Unable to forward JSDOM console output - neither sendTo nor forwardTo methods are available","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/jest-environment-jsdom-abstract/src/index.ts","lineNumber":68,"sourceCode":"    const {JSDOM, ResourceLoader, VirtualConsole} = jsdomModule;\n\n    const virtualConsole = new VirtualConsole();\n\n    if (\n      'forwardTo' in virtualConsole &&\n      typeof virtualConsole.forwardTo === 'function'\n    ) {\n      // JSDOM 27+ uses `forwardTo`\n      virtualConsole.forwardTo(context.console);\n    } else if (\n      'sendTo' in virtualConsole &&\n      typeof virtualConsole.sendTo === 'function'\n    ) {\n      // JSDOM 26 uses `sendTo`\n      virtualConsole.sendTo(context.console, {omitJSDOMErrors: true});\n    } else {\n      // Fallback for unexpected API changes\n      throw new TypeError(\n        'Unable to forward JSDOM console output - neither sendTo nor forwardTo methods are available',\n      );\n    }\n\n    virtualConsole.on('jsdomError', error => {\n      context.console.error(error);\n    });\n\n    this.dom = new JSDOM(\n      typeof projectConfig.testEnvironmentOptions.html === 'string'\n        ? projectConfig.testEnvironmentOptions.html\n        : '<!DOCTYPE html>',\n      {\n        pretendToBeVisual: true,\n        resources:\n          typeof projectConfig.testEnvironmentOptions.userAgent === 'string'\n            ? new ResourceLoader({\n                userAgent: projectConfig.testEnvironmentOptions.userAgent,","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-environment-jsdom-abstract/src/index.ts#L50-L86","documentation":"BaseJSDOMEnvironment routes JSDOM's VirtualConsole to Jest's console by calling `forwardTo` (JSDOM 27+) or `sendTo` (JSDOM 26). If the loaded jsdom module's VirtualConsole exposes neither method, the environment cannot forward browser console output and throws at index.ts:68 rather than silently dropping logs.","triggerScenarios":"Loading a jsdom version older than 26 (no sendTo/forwardTo), a fork/stub of jsdom, or a future jsdom that renames the API again. Triggered at environment construction time, before any test runs.","commonSituations":"Pinning a very old `jsdom` in package.json while using a newer `jest-environment-jsdom`; a yarn/npm resolution that pulls a different jsdom major; a custom environment that injects a mock jsdom module; jsdom releases a new major and the abstract adapter has not been updated yet.","solutions":["Upgrade `jest-environment-jsdom` to a version matching your jsdom major (jsdom 27 needs the forwardTo-aware adapter).","Pin `jsdom` to a supported major (26 or 27) in resolutions/overrides.","If you ship a custom jsdom shim, implement `forwardTo(console)` or `sendTo(console)` on its VirtualConsole.","Run `npm ls jsdom` to find the conflicting copy and dedupe."],"exampleFix":"// before (package.json)\n\"devDependencies\": {\n  \"jest-environment-jsdom\": \"^30\",\n  \"jsdom\": \"^21\"\n}\n\n// after\n\"devDependencies\": {\n  \"jest-environment-jsdom\": \"^30\",\n  \"jsdom\": \"^27\"\n}","handlingStrategy":"validation","validationCode":"const jsdom = require('jsdom');\nconst vc = new jsdom.VirtualConsole();\nif (typeof vc.forwardTo !== 'function' && typeof vc.sendTo !== 'function') {\n  throw new Error(`jsdom ${require('jsdom/package.json').version} is unsupported by this adapter`);\n}","typeGuard":"const supportsForwarding = (vc: any): boolean => typeof vc.forwardTo === 'function' || typeof vc.sendTo === 'function';","tryCatchPattern":null,"preventionTips":["Pin jsdom to a major supported by jest-environment-jsdom.","Run `npm ls jsdom` after dependency changes.","Keep jest-environment-jsdom and jsdom versions in lockstep."],"tags":["jest-environment","jsdom","version-mismatch","dependency"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}