Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are all JavaScript Console Logs and Errors showing Line 1 (Developer Tools)

I'm working on a Javascript project and using the Chrome F12 Developer Tools for debugging. For some reason all the console.log outputs and error messages claim that they are occuring on line 1 of my js file.

...i.e., in the Console to the right of each line it says myFile.js:1 even though there is no code on line 1, and the code is obviously running on a different line.

What could be the cause of this?

like image 303
Luke Avatar asked Sep 30 '22 22:09

Luke


2 Answers

Apparently other people weren't able to reproduce the problem (@Bergi), so I can only imagine that Chrome was somehow having a problem with the file (corrupted?). Clearing cache did not help.

The work-around solution that worked for me was to use a new file.

  1. Change file name to myFile_broken.js
  2. Create a new file myFile.js
  3. Copy all content from myFile_broken.js to myFile.js

The new js file now displays the correct line numbers. Despite all properties looking the same and all text content being the same, the new file had about 100 more bytes than the original broken file.

Hopefully this helps someone who has the same issue, and hopefully the root problem is one day discovered and fixed. (Error reproduced by me in Chrome versions 34.0.1847.116 m and 34.0.1847.131 m)

like image 156
Luke Avatar answered Oct 06 '22 01:10

Luke


This sounds like an issue where the line endings aren't in the correct format. It could be an issue with the settings being used by your editor, or even an issue with the way the file was copied to the server. But for whatever reason, the lines aren't being recognized as having correctly encoded endings, so it's all being seen as one line.

like image 39
Sam Hanley Avatar answered Oct 06 '22 01:10

Sam Hanley