Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

AxiosError Network Error with code ERR_NETWORK in a React app

ErrorAxiosError {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.

  • Applies to axios 1, React 19, Chrome, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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);
    });
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2Console 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. 3The 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. 4The Network tab shows the request failed with no status code.The server is down or the address is wrongFix

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, Authorization

3Verify

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

Did this fix it?

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, Authorization

3Verify

Reload the app and retry the call.

console.log('retry');

Confirmed by developer.mozilla.org

Did this fix it?

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

Did this fix it?

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/items

2Fix

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/items

Confirmed by axios.rest

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.