Showing file and line of javascript syntax error in Safari

Viewed 799

For the following error:

SyntaxError: Unexpected token '='. Expected an opening '(' before a method's parameter list.

enter image description here

Safari is not showing a proper stacktrace with file and line. Note there is no inline javascript code in the html: it is all in .js files. How can I get a better handle on where this error is occurring?

1 Answers

Per this answer that links to this post

override your window.onerror like so

window.onerror = function(message, url, linenumber) {
    alert('JavaScript error: ' + message + ' on line ' + linenumber + ' for ' + url);
}

If you're working on a production app you really should use babel, which will solve issues like this for you. If it's not solving these issues make sure to update your packages / npm etc etc.

To get a bit more technical this is because you (or one of your users) are using an outdated version of safari that officially supports only SOME of the latest and greatest javascript improvements. Upgrading Safari may also take care of this issue, depending on when you read this.

Cheers

Related