react-native: [TypeError: Network request failed]

Description

When I call fetch on my local

React Native Version

0.70.3

Output of npx react-native info

System: OS: macOS 13.0 CPU: (8) arm64 Apple M1 Pro Memory: 65.52 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.18.0 - ~/.nvm/versions/node/v16.18.0/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 8.19.2 - ~/.nvm/versions/node/v16.18.0/bin/npm Watchman: 2022.10.03.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /opt/homebrew/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: 2021.2 AI-212.5712.43.2112.8815526 Xcode: 14.2/14C18 - /usr/bin/xcodebuild Languages: Java: 11.0.16.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.1.0 => 18.1.0 react-native: 0.70.3 => 0.70.3 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

fetch(‘https://192.168.1.5:8443/nexo’, { method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, ‘x-API-key’: ‘{your-api-key}’, }, body: JSON.stringify({ …securedMessage, MessageHeader: requestBody.MessageHeader, }), }) .then(response => { console.log(‘2’); console.log(response);

                  })
                  .catch(error => {
                    console.log(error);
                  })

Snack, code example, screenshot, or link to a repository

image

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 20 (2 by maintainers)

Most upvoted comments

@lunaleaps sorry for bumping this, I think there’s something going on with network requests either with fetch or axios 1.x.x and rn 0.71.x

I get tons of network error or ERR_NETWORK with NO status code on both platforms from many different users and during our QA process on staging servers which have 0 traffic and real testing devices have stable internet. There’s definitely nothing wrong with our servers since I do not see any 4xx,5xx errors at all. It happens on our aws lambda functions and firebase functions, there’s no chance both to have networking issues.

It’s really weird.

Same here. As far as I read, it has something to do with app’s changing state cancelling fetch requests but I could not reproduce it in any way (not on Android nor on iOS) yet many of our users seem to get this error. Anyone has an idea what’s going on?

@efstathiosntonas Yeah… I just checked the error reports and they seem completely random. Some of the users that get them are on wifi, while others are on cellular so probably it’s not a router issue. Will continue looking into it, fingers crossed

@hypnocill damn that’s a really long lasting bug as it seems on native level, I wasn’t aware of it. I need to perform tests now 🤣

@efstathiosntonas Hm, it makes sense though I can’t think of what might be the issue in our case - the domain shouldn’t be the problem. I’m looking into app’s state changes cancelling requests: https://github.com/facebook/react-native/issues/35384 though with no success so far.

Thank you for answering!