Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to effectively debug minified JS files?

I've got problem debugging minified JS on production server.

While you can't catch some errors on your machine while testing dev/prod servers, there's an opportunity to send some frontend errors and exceptions from users to a special log.

When JS files are minified, debugging this code becomes a hell.
What are the best practices in performing such work?

like image 350
Sergey Solomatin Avatar asked Jul 14 '16 13:07

Sergey Solomatin


People also ask

Which file is used to debug the JavaScript files?

Javascript files can be debugged in Chrome Browser the same way you debug HTML/CSS files i.e using Chrome Developer Tools which can be launched via following shortcuts as per the OS you use.

Can we debug js file?

You can debug JavaScript and TypeScript code using Visual Studio. You can hit breakpoints, attach the debugger, inspect variables, view the call stack, and use other debugging features.


2 Answers

Biting the bullet ;) In chrome you can auto format the minified code from the sources panel click the brackets icon in the bottom left to format

Then you can add debugger statements by clicking the line numbers. Run your code and find out more...

add debugger by clicking line number

like image 65
Mettin Parzinski Avatar answered Oct 18 '22 21:10

Mettin Parzinski


So, after some time, we've continued to try and resolve damn trouble and we've stumbled upon this library that allows you to map your stack to unminified version of build.

https://github.com/mozilla/source-map

We needed this to embed to our internal system that collects error reports. There are also ready solutions across the web if don't need your own like we do:

https://raygun.com/sourcemaps

https://sourcemaps.info/

like image 9
Sergey Solomatin Avatar answered Oct 18 '22 20:10

Sergey Solomatin