Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined:1 <!DOCTYPE html> ^ SyntaxError: Unexpected token < node.js

Tags:

node.js

I left my app running when I went out and when I came back hours later the app had died with this message:

undefined:1
<!DOCTYPE html>
^
SyntaxError: Unexpected token <
    at Object.parse (native)
    at IncomingMessage.<anonymous> (/home/engine/private_js/N.app.js:35:296)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:919:16
    at process._tickCallback (node.js:419:13)

In app.js there are only 244 lines of code what kind of error is this I've not seen one like this before, google has nothing on it except a paste bin, I am sure it comes from deep in node.js

lol, server burp?

like image 432
8DK Avatar asked Jul 28 '14 22:07

8DK


People also ask

What is unexpected token in HTML?

The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. This might be a simple typo.

What does uncaught SyntaxError unexpected token mean?

Uncaught SyntaxError: Unexpected token < means server already send index. html file to chrome, but server can't find your frontend static path.

How do I fix uncaught SyntaxError unexpected identifier?

To solve the "Uncaught SyntaxError: Unexpected identifier" error, make sure you don't have any misspelled keywords, e.g. Let or Function instead of let and function , and correct any typos related to a missing or an extra comma, colon, parenthesis, quote or bracket.


1 Answers

Without seeing any code, my guess is you're trying to JSON.parse() a response from a server, but it's returning HTML instead of JSON. You should check the response's content-type to make sure it is application/json before trying to parse the response.

like image 200
mscdex Avatar answered Sep 18 '22 21:09

mscdex