[TypeError: signal.throwIfAborted is not a function (it is undefined)] in React Native context
psam44 opened this issue · comments
P Sam commented
Upgrading from 0.31.4 to 1.2.3.
Here are my traces:
LOG signal {}
LOG signal.reason undefined
LOG signal.aborted false
LOG signal.onabort null
LOG signal.throwIfAborted undefined
LOG signal.addEventListener [Function addEventListener]
LOG signal.removeEventListener [Function removeEventListener]
These are conformant with the definitions found in node_modules\react-native\types\modules\globals.d.ts
Extracts:
declare class AbortSignal implements EventTarget {
readonly aborted: boolean;
onabort: (event: AbortEvent) => void;
addEventListener: (
removeEventListener: (
Sindre Sorhus commented
This is a problem with React Native and should be reported there instead.
Andre de Waard commented
@psam44 Found a solution?
P Sam commented
@andredewaard No solution. My conclusion is to come back to v0.33 for now, and plan for elimination, as supporting this package in react-native doesn't seem to be an objective and I don't expect RN to fully implement the AbortSignal API.
Andre de Waard commented
Alright, thanks for the heads up, i reverted back to using native Fetch instead.
ibash-corpusant commented
You can polyfill:
// polyfill throwIfAborted which seems to be missing in react-native, but ky
// uses it
//
// Fun fact, AbortSignal here is just a react-native polyfill, too:
// https://github.com/facebook/react-native/blob/838d26d7b534133e75c7fa673dfc849b0e64c9d3/packages/react-native/Libraries/Core/setUpXHR.js#L38
//
// Unfortunately it doesn't have a `reason`
//
// ref: https://github.com/tjmehta/fast-abort-controller/blob/42588908035d1512f90e7299a2c70dfb708f9620/src/FastAbortSignal.ts#L39
if (!AbortSignal.prototype.throwIfAborted) {
AbortSignal.prototype.throwIfAborted = function() {
if (this.aborted) {
throw new Error('Aborted')
}
}
}