react-native: [iOS] Fetch/axios request get stuck: Promise does not get resolved

Description

When running any axios/fetch request, the Promises do not get resolved or rejected, so the thread gets stuck here. The problem is iOS only. The problem exists on debug and distributed build, on any device we tried. There might be a possibility that the problem started with the upgrade to React Native 0.72.7 (from 0.69.7).

When using Flipper for debugging, in the network tab, I can see the network request passing and getting the success response.

Code example:

console.log('sending api');
fetch('https://www.google.com')
.then(()=>{
     console.log('resolved');
}).catch(()=>{
     console.log('rejected');
});
console.log('after fetch'); 

Output:

sending api 

Solutions tried

  • Setting NSAllowsArbitraryLoads to true in Info.plist
  • Setting metro configuration to
   transformer: {
      getTransformOptions: async () => ({
        transform: {
          experimentalImportSupport: false,
          inlineRequires: false,
        },
      }),
    },
  • Tried different CocoaPods (1.12, 1.13, 1.14)
  • Applying target: “ES2017” to tsconfig.json (overriding react-native defualt tsconfig)
  • Removing ‘plugin-proposal-class-properties’ from babel.config

Connected issues:

React Native Version

0.72.7

Output of npx react-native info

System: OS: macOS 13.1 CPU: (10) arm64 Apple M1 Max Memory: 721.58 MB / 32.00 GB Shell: version: 5.8.1 path: /bin/zsh Binaries: Node: version: 18.17.1 path: ~/.nvm/versions/node/v18.17.1/bin/node Yarn: version: 1.22.19 path: /opt/homebrew/bin/yarn npm: version: 9.6.7 path: ~/.nvm/versions/node/v18.17.1/bin/npm Watchman: version: 2023.10.09.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.14.2 path: /Users/simonadenic/.rvm/gems/ruby-2.7.5/bin/pod SDKs: iOS SDK: Platforms: - DriverKit 22.2 - iOS 16.2 - macOS 13.1 - tvOS 16.1 - watchOS 9.1 Android SDK: Not Found IDEs: Android Studio: 2022.3 AI-223.8836.35.2231.11005911 Xcode: version: 14.2/14C18 path: /usr/bin/xcodebuild Languages: Java: version: 11.0.17 path: /Users/simonadenic/.jenv/shims/javac Ruby: version: 2.7.5 path: /Users/simonadenic/.rvm/rubies/ruby-2.7.5/bin/ruby npmPackages: “@react-native-community/cli”: Not Found react: installed: 18.2.0 wanted: 18.2.0 react-native: installed: 0.72.7 wanted: 0.72.7 react-native-macos: Not Found npmGlobalPackages: “react-native”: Not Found Android: hermesEnabled: true newArchEnabled: false iOS: hermesEnabled: true newArchEnabled: false

Steps to reproduce

Not completely sure about this, since our project is too big to defer.

Snack, screenshot, or link to a repository

/

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 21

Most upvoted comments

This issue was closed because it has been stalled for 7 days with no activity.

I ran into this too for android I tried the XHR workaround mentioned here but then i ran into another issue !! what worked for me is this solution here using @babel/plugin-transform-flow-strip-types along with react-native start --reset-cache, and i reverted the XHR solution.

I also encountered this problem

Is there any new finding on that issue? We’re experiencing this bug in production; it’s looking rather bad. 🥲 I would be happy to help in any way I can.