5

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?

7
  • @plalx "even though there is no code on line 1, and the code is obviously running on a different line." :) Commented Apr 26, 2014 at 17:10
  • Have you verified in the resources tab that your script is being served exactly as you want? If the server is accidentally serving another page then the error will of course be the first line. Commented Apr 26, 2014 at 17:11
  • The code is not compressed, and it's showing up fine under Resources - Frames - localhost - Scripts. There is another script being loaded and the console.log messages from it show the accurate line number. Commented Apr 26, 2014 at 17:25
  • 1
    Code is here: deathraygames.com/play-online/exo-aquatic Commented Apr 26, 2014 at 17:44
  • Can you be more specific what log you mean? I'm just getting 4 logs on that page: datadelivery.1.js:20, submarine.js:107, submarine.js:112, submarine.js:90 Commented Apr 26, 2014 at 17:46

3 Answers 3

2

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)

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! I had the exact same problem, and this fixed it. I bet it is a line ending issue.
Thanks so much! Same problem, this fixed it. You just have to make sure its a NEW js file. Dont just rename the old file
1

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.

2 Comments

Do you know of a way to determine how the line endings are encoded?
I don't offhand know of a specific good way to check the encoding, no. Maybe someone else does.
1

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.

1 Comment

I had the same issue with Chrome and also a onchange. Chrome Dev tools says just line 1 with no extra info, but Firefox is more precise.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.