-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
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.
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
Requestto the above list ofLIVING_KEYSfor jsdom - Removing
AbortControllerandAbortSignalfrom the list ofLIVING_KEYS. This means that Node's nativeAbortControllerandAbortSignalwill 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.4Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.