undici
undici copied to clipboard
Can't bring custom `abort-controller` implementation to undici.fetch
Bug Description
We are using abort-controller
from npm in our codebase with undici. undici fails with:
TypeError: AbortSignal: Expected [object AbortSignal] to be an instance of AbortSignal.
Reproducible By
https://replit.com/@SukkaW/ImaginaryDishonestCommunication#index.js
const { AbortController } = require('abort-controller');
const { fetch } = require('undici');
const controller = new AbortController()
controller.abort()
try {
fetch('https://example.com', {
signal: controller.signal,
})
} catch (error) {
console.log(error.message)
}
Expected Behavior
The error AbortError: The operation is aborted
should be shown instead.
Environment
Node.js 18.7.0 on macOS 13 Beta 4
Additional Context
I have searched the codebase of undici and I notice this:
https://github.com/nodejs/undici/blob/5890e16ddd2703151ce0be0a468e13d685b89f60/lib/fetch/request.js#L838-L840
@KhafraDev
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.
@mcollina Actually I don't know the best way to fix it.
I could simply remove the webidl interface check to address the fix, but it might not be fetch spec compliant any more.