'Promise allSettled is not a function

I planned updating some Promise.all to Promise.allSettled in my React Native - Expo Project but the function does not Exist. i checked all Versions and everything fits but i still cant use the function.

node -v: 14.15.4

expo SDK -v version: ^40.0.1

expo uses react native -v 0.63 in their SDK version. This should not be the problem. This is the error message:

Promise.allSettled is not a function

Does anybody knows a solution to this? Thank you for your help!



Solution 1:[1]

For anyone coming across this issue, apparently this was fixed in v64:

https://github.com/facebook/react-native/issues/30236#issuecomment-939286987

For older versions, you can use a simple polyfill:

Promise.allSettled = Promise.allSettled || ((promises) => Promise.all(
    promises.map(p => p
        .then(value => ({
            status: "fulfilled",
            value
        }))
        .catch(reason => ({
            status: "rejected",
            reason
        }))
    )
));

Solution 2:[2]

export const PromiseHelperAllSettled = (promises) => {
    return Promise.all(promises.map(function (promise) {
        return promise.then(function (value) {
            return { state: 'fulfilled', value: value };
        }).catch(function (reason) {
            return { state: 'rejected', reason: reason };
        });
    }));
};

import { PromiseHelperAllSettled } from './PromiseHelperAllSettled';
useEffect(() => {
if (Promise && !Promise.allSettled) {
      Promise.allSettled = PromiseHelperAllSettled;
    }
},[]);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 NullDev
Solution 2 Thaiyalnayaki.S