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

跟風遠走 提交于 2019-12-30 22:31:13

问题


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?


回答1:


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)




回答2:


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.




回答3:


I recently had a JS error which was showing as line 1 in the console. It turned out that the error was coming from inside a dynamically constructed onchange attribute.

Since the error was on the first "line" of the code inside the onchange attribute, and there was no filename associated with an inline attribute, the Firefox console got confused and showed the error as coming from line 1 of the surrounding HTML file. The Chrome console also showed it as line 1, but clicking on the error opened up the onchange handler rather than the whole html file, which is how I figured it out.



来源:https://stackoverflow.com/questions/23314033/why-are-all-javascript-console-logs-and-errors-showing-line-1-developer-tools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!