Skip to content

Using AbortController with fetch throws an error with Node 24 + jsdom #8374

@ChintanAcharya

Description

@ChintanAcharya

Describe the bug

When we create an AbortController and pass its signal to the fetch function, it throws an error that says

TypeError: RequestInit: Expected signal ("AbortSignal {}") to be an instance of AbortSignal.
Image

This happens only in the JSDom environment and when we use Node 24. The error does not happen when using the node or happy-dom environment.

I did some investigation, and it looks like Vitest is overriding the AbortController and AbortSignal globals from jsdom and Node 24's native fetch does not work with jsdom's AbortSignal implementation.

I tried a couple of possible fixes that work:

  • Adding Request to the above list of LIVING_KEYS for jsdom
  • Removing AbortController and AbortSignal from the list of LIVING_KEYS. This means that Node's native AbortController and AbortSignal will be used.

If you agree with any of these, I'm happy to raise a PR.

I'm not sure if the issue belongs here, so feel free to close/redirect if appropriate.

Thanks!

Reproduction

Can't provide StackBlitz because it uses Node 20.
Git repo: https://github.com/ChintanAcharya/vitest-jsdom-request-repro

System Info

System:
  OS: macOS 15.6
  CPU: (12) arm64 Apple M3 Pro
  Memory: 674.17 MB / 36.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 24.4.1 - ~/.nvm/versions/node/v24.4.1/bin/node
  npm: 11.4.2 - ~/.nvm/versions/node/v24.4.1/bin/npm
Browsers:
  Chrome: 138.0.7204.184
  Safari: 18.6
npmPackages:
  vitest: 3.2.4 => 3.2.4

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions