close

[Solved] Error: Network Error Stack trace

I am using Axios in my react app but unfortunately, I am facing Network Error like Error: Network Error Stack trace in ReactJS. We are going to Learn about All Possible Solutions So Lets Get Start with This Article.

How Error: Network Error Stack trace Error Occurs ?

I am using Axios in my react app but unfortunately, I am facing the following error.

Error: Network Error Stack trace:

So here I am writing all possible solutions that I have tried to resolve this error.

How To Solve Error: Network Error Stack trace Error ?

  1. How To Solve Error: Network Error Stack trace Error?

    To Solve Error: Network Error Stack trace Error If You are using Nodejs For the backend then you need to Use Cors in your nodejs app. Your Express app needs to use CORS just add below two lines in your nodejs backend’s server file: var cors = require(‘cors’); app.use(cors()); OR you can add cors just like this: app.use(cors({origin: true, credentials: true})); Now, your error must be solved.

  2. Error: Network Error Stack trace

    To Solve Error: Network Error Stack trace Error If You are using localhost URL in your Axios Then You Need to Put HTTP:// before your URL and then you have to use API. For example: const url = “http://localhost:4000/api/get_users”; Now, your error must be solved.

Solution 1: add http or https

If You are using localhost URL in your Axios Then You Need to Put HTTP:// before your URL and then you have to use API. For example.

  const headers = {
    "Content-Type": "application/json",
    Authorization: apiKey,
  };
  const url = "http://localhost:4000/api/get_users";

  axios.get(url, { headers });

Now, your error must be solved.

Solution 2: Use cors for Nodejs

If You are using Nodejs For the backend then you need to Use Cors in your nodejs app. Your Express app needs to use CORS just add below two lines in your nodejs backend’s server file.

var app = express();

// ADD THIS TWO LINE
var cors = require('cors');
app.use(cors());

OR you can add cors just like this.

app.use(cors({origin: true, credentials: true}));

Now, your error must be solved.

Summary

It’s all About this error. Hope We solved Your error. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Leave a Comment