react-native icon indicating copy to clipboard operation
react-native copied to clipboard

fetch [TypeError: Network request failed] on iOS 18.4

Open faustoct1 opened this issue 8 months ago • 55 comments

Description

fetch() was working on 18.2 and older but in the new 18.4 ios is not working it gives the error

[TypeError: Network request failed]

I ran the same code on both simulators and the desirable result didn't work as expected. It happened to me in specific apis like google maps, I tried wikipedia api, it worked! I tested with axios/fetch.

Steps to reproduce

just call google maps fetch(https://maps.googleapis.com/maps/api/place/autocomplete/json?sessiontoken=${sessionToken}&input=${text.replace(/\s+/g,"+")}&key=${this.API_KEY}&limit=10${t}&language=en) it works on ios 18.2 but fails on 18.4. it fails specifically for google maps but works to other endpoints.

React Native Version

0.76.9

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info

info Fetching system and libraries information...
System:
  OS: macOS 15.4
  CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Memory: 483.07 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.4.1
    path: ~/.nvm/versions/node/v22.4.1/bin/node
  Yarn:
    version: 1.22.21
    path: /usr/local/bin/yarn
  npm:
    version: 10.8.1
    path: ~/.nvm/versions/node/v22.4.1/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.14.3
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.4
      - iOS 18.4
      - macOS 15.4
      - tvOS 18.4
      - visionOS 2.4
      - watchOS 11.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.3 AI-243.24978.46.2431.13208083
  Xcode:
    version: 16.3/16E140
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.14
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 18.0.0
    wanted: ^18.0.0
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.9
    wanted: 0.76.9
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Stacktrace or Logs

[TypeError: Network request failed]

Reproducer

https://github.com/faustoct1/codes/blob/main/fetch-rn.js

Screenshots and Videos

No response

faustoct1 avatar Apr 06 '25 22:04 faustoct1

@faustoct1 Can you also try once on latest react-native version: 0.78.x and let us know. Thanks

devanshsaini11 avatar Apr 07 '25 12:04 devanshsaini11

@devanshsaini11

Same error on ios 18.4:

  • "react-native": "0.78.2",
  • "axios": "^1.8.4",

Image

what-is-love54 avatar Apr 07 '25 13:04 what-is-love54

Also experiencing this issue! I'm getting errors from expo-notifications and expo-file-system related to failed network requests on my iOS simulator and real device using iOS 18.4. I'm using react-native version 0.76.9. Unfortunately, I can't update to 0.78.x as I'm using many Expo libraries!

trentcowden avatar Apr 07 '25 16:04 trentcowden

Running into this too with Expo using the react-native-auth0 library which calls fetch under the hood.

The only way i've found to "get around" this via the iOS simulator is to hit Device -> Erase all content and settings to wipe the state and app binary installation, then reinstall everything.

Restarting the app with Device -> Restart to load a new JS bundle will bring back the [TypeError: Network request failed] fetch error.

johntrinhcode avatar Apr 07 '25 20:04 johntrinhcode

Looking into it more, requests are stuck in a pending status in the RN devtools.

Image

And mention an issue with Network.streamResourceContent.

Image

johntrinhcode avatar Apr 07 '25 20:04 johntrinhcode

@faustoct1 Can you also try once on latest react-native version: 0.78.x and let us know. Thanks

Hi, I'm running in a deadline I can't upgrade it for now. I'll do it as soon as I get free time. If there's a patch I can try, since it's just run a command meanwhile I'm using rn+expo, it's quite painful to upgrade, and make sure everything is working fine ! I tested on my published app and it's working, it seems to be a problem on simulator.

faustoct1 avatar Apr 07 '25 21:04 faustoct1

Running into this too with Expo using the react-native-auth0 library which calls fetch under the hood.

The only way i've found to "get around" this via the iOS simulator is to hit Device -> Erase all content and settings to wipe the state and app binary installation, then reinstall everything.

Restarting the app with Device -> Restart to load a new JS bundle will bring back the [TypeError: Network request failed] fetch error.

I had the same problem with auth. I did exactly this and it worked! I tested on my published app and it's working on a real device, the problem only happened on simulator for me.

I reported this issue here since I faced it first before the fetch issue https://github.com/react-native-google-signin/google-signin/issues/1419

faustoct1 avatar Apr 07 '25 21:04 faustoct1

I can confirm that it works fine on an iOS 18.4 physical device, but there is an error when using the iOS 18.4 simulator.

I erased the 18.4 simulator, rebuilt and installed my app; it worked for about 5 minutes, and then the same problem returned. I went back to the 18.3 simulator, and all is good. Running React Native 0.77.2

visoft avatar Apr 08 '25 00:04 visoft

I can confirm that it works fine on an iOS 18.4 physical device, but there is an error when using the iOS 18.4 simulator.

I erased the 18.4 simulator, rebuilt and installed my app; it worked for about 5 minutes, and then the same problem returned. I went back to the 18.3 simulator, and all is good. Running React Native 0.77.2

I kept iOS 18.4 due it's not happening on physical device. Those are the related issues I found on 18.4 ios simulator beside the fetch..

https://github.com/RevenueCat/purchases-ios/issues/4954 https://github.com/react-native-google-signin/google-signin/issues/1419

They can somehow be related, all of them seem to happen over the network.

faustoct1 avatar Apr 08 '25 02:04 faustoct1

Same for me. Was also able to reproduce it on physical ios devices

Steps to reproduce:

  • Open app
  • Set it to background mode (minimize it)
  • Wait for 3-5 hours
  • Open app again and attempt to make a network request

The request fails with a network error, despite the network being available (confirmed by successfully making a request using axios)

Error code:

Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." 
UserInfo={
  _kCFStreamErrorCodeKey=-4,
  NSUnderlyingError=0x600000cf6a60 {
    Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" 
    UserInfo={
      NSErrorPeerAddressKey=<REDACTED>,
      _kCFStreamErrorCodeKey=-4,
      _kCFStreamErrorDomainKey=4
    }
  },
  _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <E4C1DA73-E3D0-4950-A614-4C350ADFFF34>.<10>,
  _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <E4C1DA73-E3D0-4950-A614-4C350ADFFF34>.<10>"
  ),
  NSLocalizedDescription=The network connection was lost.,
  NSErrorFailingURLStringKey=https://<REDACTED>,
  NSErrorFailingURLKey=https://<REDACTED>,
  _kCFStreamErrorDomainKey=4
}

Additional Notes: • This issue only appears after the app is in the background for an extended period. • Other requests (e.g. via axios) work fine after resuming. • Might be related to iOS’s handling of backgrounded apps and stale network sessions. • Occurs consistently on React Native 0.74.x through 0.76.x (have not tested other versions yet).

yvhnpmsky avatar Apr 08 '25 07:04 yvhnpmsky

Same problem for us. We have this in revenue cat (react-native-purchases) and firebase (react-native-firebase) also sometimes acts up.

felixspitzer avatar Apr 08 '25 11:04 felixspitzer

This is an issue that affects iOS 18.4 simulators only. Check this thread for more info.

d-moreira avatar Apr 09 '25 13:04 d-moreira

I had the same problem, but for a website running through Cloudflare - React Native app does requests to it. I temporarily disabled HTTP 3 there and everything worked. Not the best way, but there are too many problems with HTTP 3, as everyone has their own implementation of the protocol. I'll wait for a fix from Apple for 18.4 at least.

Rolling back to old xcode to use old simulators is much longer and will only hinder development if working on multiple projects.

revenkroz avatar Apr 14 '25 18:04 revenkroz

I have the same issue. When I build the new app by uninstalling and reinstalling it, it works fine. However, after reloading, the network stops working.

sagarv1997 avatar Apr 15 '25 05:04 sagarv1997

Same here

KristianLentino99 avatar Apr 15 '25 20:04 KristianLentino99

same here using RN 0.76.9 and iOS 18.4.

donald-boosted avatar Apr 15 '25 21:04 donald-boosted

Have same issue on 18.3 and 18.4 simulators and one real device (18.3). This issue appears periodically and resolves automatically.

On last week I faced with this issue on real device on application version from App Store

Zao721 avatar Apr 17 '25 09:04 Zao721

I have this issue on:

IOS simulator version 18.3 
React Native: 0.74.1
Expo: "^51.0.5"

android emulator works fine.

ghasemikasra39 avatar Apr 17 '25 10:04 ghasemikasra39

Same issue here. I was also able to reproduce it on a real device and emulator. Axios requests work, but fetch does not. Everything works fine on Android, looks like only ios is affected

react-native: 0.76.9
expo: "^52.0.44

priemskiyyy avatar Apr 17 '25 13:04 priemskiyyy

"expo": "^52.0.46", "react-native": "0.76.9"

Same here, it happens after a few refreshes. Tried with node 18, node 20.18 and node 20.19.

Safari wont open the page because the network connectin was lost.

This may be an IOS 18.4 simulator issue or Xcode 16.3 issue. Either way you cant install an older IOS simulator if you have Xcode 16 installed... I may wait for a fix or downgrade to Xcode 17.5

eybel avatar Apr 17 '25 15:04 eybel

yes I had to downgrade Xcode to 16.2 and use a simulator with iOS 18.3

donald-boosted avatar Apr 17 '25 16:04 donald-boosted

My observations on the problem:

Simulator: iOS 18.4 (Xcode 16.3, macOS 15.4)

url's:

  • https://clients3.google.com/generate_204
  • https://www.google.com/recaptcha/api.js

In the application, a network error occurs when executing the fetch function. There is no problem when opening the same link in Simulator's Safari browser.

astrahov avatar Apr 18 '25 10:04 astrahov

Xcode 16.3 and iOS 18.3 sim is a working combo for me. As already pointed out, this is most likely an issue with 18.4 sim.

pehagg avatar Apr 18 '25 12:04 pehagg

Came back to give my feedback and indeed I downgraded to IOS18.3 with Xcode 16.3 and the network error is gone. No need to downgrade Xcode, only the IOS for the simulator.

I use the iPhone 15 Pro with IOS 18.3 and Xcode 16.3 and no error so far.

The problem seems to be the IOS 18.4

eybel avatar Apr 18 '25 18:04 eybel

same issue fixed by downgrading to iOS 18.3 on sim.

aneym avatar Apr 18 '25 18:04 aneym

No need to downgrade Xcode folks, just download iOS Sim 18.3.1 using Xcode.

jimji1005 avatar Apr 23 '25 16:04 jimji1005

I can attest, this is a IOS 18.4 simulator issue, im also having issues with authentication using firebase and i just keep getting unknown network errors. Downgrading to 18.2 works fine. Need to test on real device but assuming itll be okay.

asimak4 avatar Apr 24 '25 15:04 asimak4

same

AmatoGiulio avatar Apr 24 '25 20:04 AmatoGiulio

Hitting the same problems - network errors when app runs in Simulator with iOS 18.4. Occasionally network errors also affect Safari, but that is intermittent. Downgrade to 18.3 resolves the issue. Never saw the issue on real device with 18.4, but I only tested few times manually (contrary to Maestro testing in Simulator).

abbbe avatar Apr 25 '25 16:04 abbbe

Any solution please. Other than downgrade!

Biplovkumar avatar Apr 28 '25 10:04 Biplovkumar