When loading my page in Google Chrome, I get a vague error in the console:
Uncaught SyntaxError: Unexpected end of input
I have no idea what is causing it. How would I go about debugging this error?
When loading my page in Google Chrome, I get a vague error in the console:
Uncaught SyntaxError: Unexpected end of input
I have no idea what is causing it. How would I go about debugging this error?
My problem was with Google Chrome cache. I tested this by running my web application on Firefox and I didn't got that error there. So then I decided trying emptying cache of Google Chrome and it worked.
In cases where your JavaScript code is minified to a single line, another cause for this error is using // instead of /**/ for your comments.
Bad (comments out everything after // including the closing } for your function)
function example() { //comment console.log('TEST'); }
Good (confines your comment)
function example() { /* comment */ console.log('TEST'); }
In my case I was adding javascript dynamicly and using double quotes 2 times in string templates so i changed the second to single quotes and the error was gone. I hope it will help some of the people coming here for the same reason.
Trying to parse an empty JSON can be the cause of this error.
When you receive a response from the server or whatever, check first if it's not empty. For example:
function parseJSON(response) {
if (response.status === 204 || response.status === 205) {
return null;
}
return response.json();
}
Then you can fetch with:
fetch(url, options).then(parseJSON);
I had this error and fixed it by adding the guard on readyState and status shown here:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Your code here
}
};
if you got error at Anchor tag,just replace "Onclick" with "href" or "href" with "Onclick"
Setting the Accept header to application/json in the request worked for me when I faced the same problem.
In my case, i had low internet speed, when i turn off the other user's internet connection then error has gone, strange
One of the reasons for this error can be network infrastructure. I've got this problem by using a web proxy service from Cloudflare. As soon as I disable proxy and cleared browser cache it started working. So check the status of your network components too. In my case it was communicated at Cloudflare status page
