Stop Painful JavaScript Debug and Embrace Intellij with Source Map

jbardon⚡
Jan 19, 2018 · 3 min read
Image for post
Picture by @worthyofelegance from Unsplash

I prefer to use IntelliJ to debug JavaScript instead of using browser tools. It’s for sure much more convenient and effective.

Let’s use projects bundled with Browserify and Webpack (no matter the framework).

First, install the JetBrains IDE Support Chrome extension. This will bind the browser debugger environment with IntelliJ in real-time.

Image for post

Then, let’s open up our IDE and create a JavaScript Debug run configuration. Only two inputs to fill: your app running URL (local or remote) and JS files root directory Remote URL.

Launch the configuration in debug mode and then set a breakpoint in your code (a check mark appears).

Image for post
Your app will be launched on Chrome in debug mode.

Bundlers help to merge sources into a single JS file. By default, there are no ways to perform the reverse action to debug from sources. Except if you ask your bundler to generate a source map file and link it to the bundled file.

// General notation, comment sign must be included! 
//# sourceMappingURL=main.js.map
// Bundlers notation (to check if source map has been generated)
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ....

Activate source map generation in bundlers is straightforward for both bundlers. Enable debug mode in Browserify or set devtool value in Webpack configuration.

Webpack can generate source map for a production environment in an optimized way.

The debug configuration in IntelliJ is a bit different with webpack-dev-server, bundled files are deployed on webpack:///.

To debug the app, the project Remote URL must be set to this value (do not omit the dot). Note the JS files root directory Remote URL still on localhost.

References about this topic

If you encounter any troubles with debug configuration and Webpack, take a look at this JetBrains post:

For complete information about how source map works read Mozilla documentation. To see what source map file looks like, read this blog post.

Image for post
Image for post

Thank you for reading, I hope you enjoyed reading this article and it will help

If you found this article useful, please click on the 👏 button a few times to make others find the article and to show your support! 👊

Don’t forget to follow me to get notified of my upcoming articles 🙏

Check out my Other Articles

Originally published at www.linkedin.com on January 19, 2018.

DailyJS

JavaScript news and opinion.

jbardon⚡

Written by

Avid learner about web development 🔍 and writer ✍️ for sharing tips and tricks — Full-Stack Developer @SmarAdServer ➕

DailyJS

DailyJS

JavaScript news and opinion.

jbardon⚡

Written by

Avid learner about web development 🔍 and writer ✍️ for sharing tips and tricks — Full-Stack Developer @SmarAdServer ➕

DailyJS

DailyJS

JavaScript news and opinion.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store