AxiosError Network Error with code ERR_NETWORK in a React app
AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK'}Short answer
ERR_NETWORK means the request produced no readable response. In the browser the real reason is hidden from your code, so open the console and the Network tab: it is usually a CORS block, a mixed-content block, or a server that is down. Fix the one the console names.
Fix it fast
1Find out which cause you have
Axios cannot tell your code the real reason, so read the browser console. The red line above the AxiosError names the actual problem.
axios.get(url).catch((error) => { console.log(axios.isAxiosError(error), error.code, error.message); });2Match what you see, then jump to its fix
- 1
The console says the request was blocked by CORS policy, or the Network tab shows a failed OPTIONS request.The server does not send CORS headersFix - 2
Console says a header is missing in Access-Control-Allow-Headers from the preflight.A request header makes the browser send a preflight the server rejectsFix - 3
The console mentions mixed content, or the page is on https and the API URL starts with http.The browser blocks the request for security reasons other than CORSFix - 4
The Network tab shows the request failed with no status code.The server is down or the address is wrongFix
- 1
What does the error look like?
AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK'}Network Error
Cause 1 of 4
The server does not send CORS headers
1Check
Look at the response headers of the request in the Network tab. Without Access-Control-Allow-Origin the browser blocks the response.
curl -i -X OPTIONS https://api.example.com/items -H "Origin: https://app.example.com" -H "Access-Control-Request-Method: GET"2Fix
Make the server answer with Access-Control-Allow-Origin set to your app origin, and answer the preflight OPTIONS request with success. With cookies, also send Access-Control-Allow-Credentials: true and use an exact origin, not *.
Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Methods: GET, POST, PUT
Access-Control-Allow-Headers: Content-Type, Authorization3Verify
Repeat the preflight request and look for the headers in the response.
curl -i -X OPTIONS https://api.example.com/items -H "Origin: https://app.example.com" -H "Access-Control-Request-Method: GET"Confirmed by developer.mozilla.org
Cause 2 of 4
A request header makes the browser send a preflight the server rejects
1Check
A custom header such as Authorization, or a method other than GET, HEAD or POST, triggers a preflight request.
grep -rn "headers" src/api/2Fix
Add the header name to Access-Control-Allow-Headers on the server, or remove the custom header from the request.
Access-Control-Allow-Headers: Content-Type, Authorization3Verify
Reload the app and retry the call.
console.log('retry');Confirmed by developer.mozilla.org
Cause 3 of 4
The browser blocks the request for security reasons other than CORS
1Check
The axios docs list CORS and Mixed Content violations as causes of ERR_NETWORK in the browser.
grep -rn "http://" src/2Fix
Call the API over the same secure scheme as the page.
axios.get('https://api.example.com/items');3Verify
Reload the page and check that the request succeeds in the Network tab.
console.log(error.code);Confirmed by axios.rest
Cause 4 of 4
The server is down or the address is wrong
1Check
In the browser, a refused connection also appears as ERR_NETWORK. In Node.js axios reports ECONNREFUSED instead.
curl -I https://api.example.com/items2Fix
Start the server or correct the base URL, port or protocol in the axios call.
axios.create({ baseURL: 'https://api.example.com' });3Verify
Repeat the request.
curl -I https://api.example.com/itemsConfirmed by axios.rest
How do I stop it coming back?
- Set the allowed origin per environment instead of * so cookies and tokens keep working.
- Branch on error.response, error.request and error.message so real failures are logged with their detail.
- Use the same scheme for the page and the API.
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fixWeb apps
Axios returns 401 from a React app but the login works elsewhere
Error: Request failed with status code 401
A 401 means the server received the request without valid credentials.
3 causes, each with a fixWeb apps
An axios call never finishes when the API server stops answering
code: 'ECONNABORTED'
Axios has no timeout unless you give it one: the default is 0, which means wait forever.
3 causes, each with a fixWeb apps
Axios sends no cookie to an Express API even with withCredentials set to true
The login response has a Set-Cookie header, but the browser stores nothing
withCredentials only tells the browser to attach cookies.
4 causes, each with a fix