Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 306
jovan Avatar asked Feb 16 '26 20:02

jovan


2 Answers

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
        }))
    )
));
like image 77
NullDev Avatar answered Feb 19 '26 08:02

NullDev


React Native uses https://github.com/then/promise for Promises and only in version 8.2.0 it was added with allSettled. React Ntaive team updated to this version only in 0.70.6 (here list of changes including promise version bumping to 8.3.0 https://github.com/facebook/react-native/releases/tag/v0.70.6)

like image 37
Kirill Novikov Avatar answered Feb 19 '26 08:02

Kirill Novikov