Sean D
Sean D

Reputation: 4292

Axios: Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined

I am getting the title error after running the following function in React:

  const postToApi = (event) => {
    event.preventDefault();
    axios.post(process.env.API_POST_URL, {step : "3"}) 
      // API_POST_URL: http://localhost:4000/api/donate
      .then(res => {
        console.log(res);
        console.log(res.data);
      })
  };

My React app is on localhost:3000. Mentioning this because the file causing the error is: isURLSameOrigin.js:51

Upvotes: 3

Views: 16364

Answers (1)

Jacob Bralish
Jacob Bralish

Reputation: 271

Have you recently added the URL to your .env? If so, try stopping your npm/yarn and start it again. Applications compile your .env at the beginning of your dev server. If that does not work have you tried placing the URL directly into it?

Upvotes: 7

Related Questions