title: Getting Error: TypeError: Failed to fetch
body: <p>I am passing user input data from React js to node js i.e backend, by using <strong>fetch api</strong> and successfully storing the data to my database. But <strong>fetch api</strong> is not returning the object successfully and always showing me <strong>window.alert('Registration failed')</strong> and showing the following error in console. I tried every solution but not working.</p>
  <p><strong>Error Screenshot</strong>
  <a href="https://i.stack.imgur.com/IV0ph.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IV0ph.jpg" alt="enter image description here" /></a></p>
  <p><strong>CustomerRegistration.jsx</strong></p>
  <pre><code>const onSubmit = async () =&gt; {
          
          const { fname, lname, email, password, address } = state;
  
          try {
              res = await fetch('/customer-registration', {
                  method: 'POST',
                  headers: {
                      &quot;Content-Type&quot;: &quot;application/json&quot;,
      
                  },
                  body: JSON.stringify({
                      fname: fname, lname: lname, email: email, password: password, address: address
                  })
              })
  
              const data =  res.json();
              console.log(`my data ${data}`);
  
              if (data) {
                  window.alert('Customer registered successfully');
              }
  
          } catch (error) {
              window.alert('Registration failed');
              console.log(error);
          }
      }
  </code></pre>