That is why I posed the question the way I did.
If you know that the version of your Docker package and the Node version of Slim is completely the same as before you relaunched with 4.7.0 then look elsewhere.
But the other day I researched your problem with the failing json return to your query.
I found recent references to "the same error message" showing up in the last couple of weeks that seemed to track back to Slim and Docker packages.
But I find frequently that your response is associated with it being returned as html as in a html body instead of as a valid json file format.
205 votes
The wording of the error message corresponds to what you get from Google Chrome when you run JSON.parse('<...')
. I know you said the server is setting Content-Type:application/json
, but I am led to believe the response body is actually HTML.
Feed.js:94 undefined "parsererror" "SyntaxError: Unexpected token < in JSON at position 0"
with the line console.error(this.props.url, status, err.toString())
underlined.
The err
was actually thrown within jQuery
, and passed to you as a variable err
. The reason that line is underlined is simply because that is where you are logging it.
I would suggest that you add to your logging. Looking at the actual xhr
(XMLHttpRequest) properties to learn more about the response. Try adding console.warn(xhr.responseText)
and you will most likely see the HTML that is being received.
You can also got to Developer Settings -> Network Tab to see the response which you are actually getting.
This happens when you are running backend and frontend on the same server (e.g., localhost). To fix that, in the package.json
inside your root project folder, add this line: "proxy": "http://localhost:5000"
, (or your port instead of 5000
you want your request back).
– Shivam Jha
Sep 23, 2020 at 7:19
Other experiences with a solution that you may already know do not apply:
You are getting an html file instead of json.
Html files begin with <!DOCTYPE html>
.
I "achieved" this error by forgetting the https://
in my fetch
method:
fetch(`/api.github.com/users/${login}`)
.then(response => response.json())
.then(setData);
I verified my hunch:
I logged the response as text instead of JSON.
fetch(`/api.github.com/users/${login}`)
.then(response => response.text())
.then(text => console.log(text))
.then(setData);
> Yep, an html file.
>
> ## Solution:
>
> I fixed the error by adding back the `https://` in my `fetch` method.
>
> ```
> fetch(`https://api.github.com/users/${login}`)
> .then(response => response.json())
> .then(setData)
> .catch(error => (console.log(error)));
> ```