Axios returns Network Error in a React Native app on iPhone or the iOS Simulator
AxiosError: Network ErrorShort answer
A Network Error means iOS stopped the request before any HTTP answer came back. CORS is not involved in a native app. The three iOS-only causes are App Transport Security refusing a plain http URL, local network access denied on a real iPhone, and an https server whose certificate fails the checks.
Fix it fast
1Find out which cause you have
Log the code and whether any response arrived. An error without a response means the request never completed, so the status code and the body are not available to read. Then note where it fails: simulator only, device only, or both. The causes below split along that line.
axios.get(url).catch((error) => { console.log(error.code, error.message); console.log('server answered:', Boolean(error.response)); });2Match what you see, then jump to its fix
- 1
The failing URL starts with http://, and it fails on the simulator and on a device alike. Switching the same address to https works.App Transport Security blocks a plain http URLFix - 2
The app reaches a server on your computer, such as 192.168.1.20 or a .local name, from the simulator but not from a phone.Local network access is denied on a real iPhoneFix - 3
The URL is https, and the request fails on the simulator and on the device, while the same URL opens in a desktop browser.The https server fails the certificate or ATS checksFix
- 1
What does the error look like?
AxiosError: Network Errorerror.code is ERR_NETWORK and error.response is undefinedThe same request works on Android, in a browser, or on the iOS Simulator and fails on an iPhone
Cause 1 of 3
App Transport Security blocks a plain http URL
1Check
iOS enforces App Transport Security, which requires https. The React Native networking guide says a cleartext URL needs an exception in Info.plist, and that you should name the one domain instead of switching ATS off for the whole app.
grep -rn "http://" src/ .env* 2>/dev/null2Fix
Move the API to https. If that is not possible for a development server, add an exception for that single host.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>dev.example.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>3Verify
Rebuild the iOS app, because Info.plist is a native file, and repeat the request.
npx react-native run-iosConfirmed by reactnative.dev
Cause 2 of 3
Local network access is denied on a real iPhone
1Check
Apple says outgoing traffic to a local network address needs local network access, and the simulator does not support local network privacy, so only a device shows the problem. A local network means an interface such as Wi-Fi or Ethernet, not cellular or VPN. Look at the switch in Settings.
# on the iPhone:
# Settings > Privacy & Security > Local Network > your app
grep -n "NSLocalNetworkUsageDescription" ios/*/Info.plist2Fix
Add NSLocalNetworkUsageDescription to Info.plist with a short reason, so iOS can ask. Then switch the app on under Local Network in Settings, and keep the phone on the same Wi-Fi network as your computer. When access is granted later, the system retries the connection by itself.
<key>NSLocalNetworkUsageDescription</key>
<string>The app talks to the development API on your local network.</string>3Verify
Run the app on the phone, allow the Local Network prompt, and repeat the request.
npx react-native run-iosConfirmed by developer.apple.com
Cause 3 of 3
The https server fails the certificate or ATS checks
1Check
Apple's nscurl tool runs the same checks ATS does and prints PASS or FAIL for each setting. If it fails even with arbitrary loads allowed, the certificate itself is the problem: it must match the server's DNS name and must not be expired, among other requirements.
/usr/bin/nscurl --ats-diagnostics --verbose https://api.example.com2Fix
Fix the certificate or the server settings that nscurl reports, for example install a certificate that matches the host name and is still valid. Add an ATS exception for the domain only for something the server cannot change.
# after the server change, the first test in the output should show:
/usr/bin/nscurl --ats-diagnostics --verbose https://api.example.com3Verify
The default configuration test in the nscurl output shows Result : PASS, and the app request succeeds.
/usr/bin/nscurl --ats-diagnostics --verbose https://api.example.com | grep ResultConfirmed by developer.apple.com
How do I stop it coming back?
- Use https for every API address from the first day, including the development server.
- Add the NSLocalNetworkUsageDescription text once, when the project is created, if the app is ever tested against a server on your computer.
- Test every networking change on a real iPhone as well as the simulator.
- Log error.code and error.response in one shared Axios error handler.
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
iOS app cannot load an http:// URL because App Transport Security blocks it
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
App Transport Security (ATS) makes every URLSession request use HTTPS with a modern TLS setup.
4 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
fetch fails with TypeError: Network request failed in React Native
Network request failed
Network request failed means the request never got an HTTP response, so there is no status code to read.
3 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 fix