fetch fails with TypeError: Network request failed in React Native
TypeError: Network request failedShort answer
Network request failed means the request never got an HTTP response, so there is no status code to read. In React Native the common causes are plain http URLs that iOS App Transport Security or Android cleartext rules block, and a self-signed development certificate that Android does not trust. Check the URL scheme first.
Fix it fast
1Find out which cause you have
Print the exact URL and the full error. If the URL starts with http:// and the failure happens in a release or newer-OS build, start with the first cause. If it is https:// with a certificate you made yourself, jump to the third.
try { const res = await fetch(url); console.log(res.status); } catch (e) { console.error('fetch failed for', url, e); }2Match what you see, then jump to its fix
- 1
Fails only on iOS, URL begins with http://iOS blocks a plain http URL (App Transport Security)Fix - 2
Fails only on Android 9 (API 28) or newer, URL begins with http://Android blocks cleartext http trafficFix - 3
https:// URL with a certificate from your own CA, works in a desktop browser or curl -k, fails on AndroidAndroid does not trust your self-signed development certificateFix
- 1
What does the error look like?
TypeError: Network request failedNetwork request failed
Cause 1 of 3
iOS blocks a plain http URL (App Transport Security)
1Check
iOS enforces App Transport Security by default, so an http:// request is refused unless the app declares an exception.
grep -n "NSAppTransportSecurity" ios/*/Info.plist2Fix
Best fix: serve the API over https. If you must call http, add an exception for that one domain under NSAppTransportSecurity / NSExceptionDomains in Info.plist instead of turning ATS off for the whole app.
<!-- ios/<App>/Info.plist: keep the exception per domain -->
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<!-- add your host and its insecure-load setting here, as in Apple's ATS docs -->
</dict>
</dict>3Verify
Rebuild the iOS app (an Info.plist change needs a native rebuild, not a Metro reload) and repeat the request.
npx react-native run-iosConfirmed by reactnative.dev
Cause 2 of 3
Android blocks cleartext http traffic
1Check
From API level 28, cleartext traffic is blocked by default. Look for usesCleartextTraffic or a network security config in the manifest.
grep -n "usesCleartextTraffic\|networkSecurityConfig" android/app/src/main/AndroidManifest.xml2Fix
Prefer https. If http is needed for one host, opt in for that domain through a network security config. The app-wide switch android:usesCleartextTraffic also works, but the Android docs advise avoiding broad cleartext permission.
<!-- android/app/src/main/res/xml/network_security_config.xml -->
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">insecure.example.com</domain>
</domain-config>
</network-security-config>
<!-- AndroidManifest.xml, on the <application> tag -->
android:networkSecurityConfig="@xml/network_security_config"3Verify
Rebuild and install the Android app, then repeat the request.
npx react-native run-androidConfirmed by developer.android.com
Cause 3 of 3
Android does not trust your self-signed development certificate
1Check
A server with a self-signed certificate or one from a private CA is not trusted by the pre-installed system CAs.
curl -v https://dev.example.com/health2Fix
Add the CA certificate to res/raw and trust it only in debug builds with debug-overrides. Android applies that block only when the app is debuggable, so a release build is unaffected.
<!-- res/xml/network_security_config.xml -->
<network-security-config>
<debug-overrides>
<trust-anchors>
<certificates src="@raw/debug_cas"/>
</trust-anchors>
</debug-overrides>
</network-security-config>3Verify
Run a debug build and repeat the request. Confirm a release build still uses only the system CAs.
npx react-native run-android --mode debugConfirmed by developer.android.com
How do I stop it coming back?
- Use https URLs for every environment, including staging, so no cleartext exceptions are needed.
- Keep any exception per domain, never app-wide.
- Always wrap fetch in try/catch and log the URL, because errors thrown by fetch are otherwise dropped silently.
- Test on a real build of both platforms after any Info.plist or manifest change.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Mobile apps
Axios request works on iOS or in a browser but fails on Android with Network Error
AxiosError: Network Error
A React Native app has no CORS, so on Android a Network Error usually means the request never reached the server.
3 causes, each with a fixMobile apps
Axios returns Network Error in a React Native app on iPhone or the iOS Simulator
error.code is ERR_NETWORK and error.response is undefined
A Network Error means iOS stopped the request before any HTTP answer came back.
3 causes, each with a fixMobile apps
backgroundImage: url(...) does nothing in a React Native view
ImageBackground renders an empty area
In React Native the backgroundImage style draws linear and radial gradients, not pictures, so url(...) is ignored.
3 causes, each with a fixMobile apps
A custom font in React Native falls back to the system font
Unrecognized font family 'MyFont'
React Native does not report a missing font, it just draws the system font.
6 causes, each with a fixMobile apps
react-native-geolocation-service getCurrentPosition fails or never returns
Location provider not available
Read the error code in the callback.
5 causes, each with a fixMobile apps
A remote image in React Native shows nothing, or only for some URLs
The same component works with one URL and stays blank with another
A network image in React Native is blank for four reasons.
4 causes, each with a fix