TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
See original GitHub issueexport 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:
- Created 6 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Running into the same issue with Parcel v2.0beta.3 😕
Seems like this is still a thing. I’m using:
On server side it’s working as expected, but when I try something like making a call inside a simple
useEffectI get the error. The workaround of usingconst fetch = unfetch.bind()worked for me as well.