react-native: Promise.allSettled is still undefined in 0.70.6 on iOS and Android with Hermes
Description
Promise.allSettled is still undefined on iOS and Android with Hermes when you have installed both latests versions of react native and expo (on a bare react native project).
It seems to work fine when executing tests with jest, however.
yarn why v1.22.19
[1/4] ๐ค Why do we have the module "promise"...?
[2/4] ๐ Initialising dependency graph...
[3/4] ๐ Finding dependency...
[4/4] ๐ก Calculating file sizes...
=> Found "promise@8.3.0"
info Reasons this module exists
- "react-native" depends on it
- Hoisted from "react-native#promise"
info Disk size without dependencies: "244KB"
info Disk size with unique dependencies: "296KB"
info Disk size with transitive dependencies: "296KB"
info Number of shared dependencies: 1
=> Found "fbjs#promise@7.3.1"
info This module exists because "expo#fbemitter#fbjs" depends on it.
info Disk size without dependencies: "220KB"
info Disk size with unique dependencies: "272KB"
info Disk size with transitive dependencies: "272KB"
info Number of shared dependencies: 1
โจ Done in 0.25s.
Version
0.70.6
Output of npx react-native info
info Fetching system and libraries information...
System:
OS: macOS 12.6
CPU: (10) arm64 Apple M1 Pro
Memory: 658.97 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.16.0 - ~/.asdf/installs/nodejs/16.16.0/bin/node
Yarn: 1.22.19 - ~/.asdf/installs/nodejs/16.16.0/bin/yarn
npm: 8.11.0 - ~/.asdf/plugins/nodejs/shims/npm
Watchman: 2022.09.19.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /Users/rarroyo/.asdf/shims/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: 2021.3 AI-213.7172.25.2113.9014738
Xcode: 14.1/14B47b - /usr/bin/xcodebuild
Languages:
Java: 11.0.16.1 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.70.6 => 0.70.6
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Steps to reproduce
1.- Have react native 0.70.6 installed. 2.- Have expo installed on a bare react native application following their documentation. 3.- Use Promise.allSettled. 4.- Get [TypeError: undefined is not a function].
Snack, code example, screenshot, or link to a repository
const results = await Promise.allSettled([promise1, promise2])
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 16
- Comments: 15 (1 by maintainers)
I ran into this, and the reason was Sentry. They patch the global Promise ๐
If you use sentry and disable it in development, thatโs how you end up with a production only crash.
Check this sentry issue and their troubleshooting guide
Appears to still be an issue in
0.72.6Iโm using
"expo": "~49.0.6"and"react-native": "0.72.6"and the issue is remaining only in production. I found a temporary workaround in hereI am also observing this issue with React Native 0.75 in our non-debug builds. My workaround was to replace all occurrences of
Promise.allSettledwithpromiseAllSettledand define this helper function somewhere:promise@8.3.0will be used for aJSCengine orjestenvironment, as I understand the latestHermeshas own implementation ofPromisesee:
https://github.com/facebook/react-native/blob/436da18fce99af6361bae5719cfce0ed4539a3f7/Libraries/Core/polyfillPromise.js#L23-L37
to test:
So, better to create issue in an appropriate repo
On the React Native 0.76 with Expo 52, if you use Yarn the fix is to add the following resolution to your package.json. No other steps from the sentry troubleshooting guide are required (no need to disable auto-patching).
Same here:
We are also experiencing the same error when using
Promise.allSettled. It somehow only happens with production build. The production build is using Hermes and we are using React Native v0.74.5Iโm getting loads of issue reports on Sentry for
TypeError: undefined is not a functionwhen callingPromise.allSettled(promises)All issues are on Android and Hermes for RN 0.72.4. But I canโt replicate on the devices I have at hand, really weird.