TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation

See original GitHub issue
export const sendSuggestion = ((data: any): Promise<any> => {
  console.log(JSON.stringify(data));
const apiUrl = `/api/suggest/`;
return fetch(apiUrl, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(checkStatus)
    .then(r => r.json())
    .then(data => {
        console.log(data);
    });
});

const checkStatus = ((response: any) => {
  if (response.ok) {
    return response;
  } else {
    var error = new Error(response.statusText);
    console.log(error);
  //return Promise.reject(error);
  }
})

The script crashed with error TypeError: Failed to execute ‘fetch’ on ‘Window’: Illegal invocation After webkack it is looks:


exports.sendSuggestion = function (data) {
    var apiUrl = "/api/suggest/";
    return unfetch_1.default(apiUrl, {             //Code crashed here
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(data)
    }).then(checkStatus).then(function (r) {
        return r.json();
    }).then(function (data) {
        console.log(data);
    });
};
var checkStatus = function checkStatus(response) {
    if (response.ok) {
        return response;
    } else {
        var error = new Error(response.statusText);
        console.log(error);
    }
};

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
jbaitercommented, Jun 22, 2021

Running into the same issue with Parcel v2.0beta.3 😕

0reactions
LasaleFaminecommented, Nov 11, 2019

Seems like this is still a thing. I’m using:

  • isomorphic-unfetch 3.0.0
  • next 9.1.3
  • react 16.11.0

On server side it’s working as expected, but when I try something like making a call inside a simple useEffect I get the error. The workaround of using const fetch = unfetch.bind() worked for me as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to execute 'fetch' on 'Window': Illegal invocation - Stack ...
and performRequest throws this error ( Fetch TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation ). I've changed it to:
Read more >
[SOLVED] Failed to execute 'fetch' on 'Window' - Moralis Forum
Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': 1 argument required, but only 0 present.
Read more >
Failed to execute 'fetch' on 'Window': Illegal invocation
Hi there,. I'm attempting to integrate my airtable database api into a React project. I installed airtable using 'npm install airtable'.
Read more >
Failed to execute 'fetch' on 'Window': Illegal invocation ...
Javascript – “Uncaught TypeError: Illegal invocation” in Chrome. In your code you are assigning a native method to a property of custom object....
Read more >
Javascript Uncaught TypeError: Illegal Invocation - Reddit
console.log requires to be called in the scope of console. Applying a different scope through .call(null, ...) will lead to the error you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found