Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uglification error: Print the line number and actual source file #228

Closed
lewisdiamond opened this issue Jul 8, 2014 · 5 comments
Closed

Comments

@lewisdiamond
Copy link

When there's a Javascript error, the grunt uglify task doesn't print a very helpful message:

Warning: Uglification failed.
Unexpected token: punc (}).
Line 57 in src/myapp.js,src/alerts.js,src/extensions.js,src/nodeserialize.js,src/view.js
Use --force to continue.

The error is on line 57 of a file made by concatenating all my files. This concatenation isn't readily available either (I haven't found this temp file on my drive, you can always manually concat them but it doesn't mean the line numbers will match).

It would be much better if it would print the actual source file and the line number inside that source file.

@UltCombo
Copy link
Contributor

UltCombo commented Jul 8, 2014

Maybe run your files individually through grunt-contrib-jshint before attempting uglification?

By the way, most IDEs and text editors support JSHint through extensions/plugins. This provides a faster feedback cycle than looking at the console and mapping the errors back to the editor manually.

@lewisdiamond
Copy link
Author

@UltCombo there are a thousand ways around it, which doesn't mean the error message should be so useless.

@UltCombo
Copy link
Contributor

UltCombo commented Jul 8, 2014

I've just tried to uglify a file with invalid syntax, the line numbers are correct for me. The error message outputs a comma-separated list of files instead of the file which threw the error, though. This seems to be due to the src array being coerced into a string.

I don't know how easy or hard it would be to workaround this issue, seeing as the error is thrown from inside the Uglify2 library (it would probably need storing and passing around the current file before attempting to parse it with Uglify). I would just take one of the thousand ways around it meanwhile.

@lewisdiamond
Copy link
Author

From what I could see, the line number is incorrect. The line number displayed refers to the line number of the result of the concatenation of all uglified files. It's not the line number of the correct file (unless that file is the first file of the concatenation).

p.s. Wouldn't it be simple to just uglify the files separately before concatenating them?

@UltCombo
Copy link
Contributor

UltCombo commented Jul 8, 2014

@lewisdiamond I've tested it by uglifying two files inside of a folder (src: dir/*.js). I've inserted syntax errors on each them, one file at a time, and the error pointed to the correct line inside of the file that contained syntax errors.

And as far as I can see, each file is compiled individually inside of a forEach loop. Perhaps there is another issue with how your gruntfile is set up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants