Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React debug in browser when using bundle.js

Tags:

Tools: Chrome Developer Tools, ReactJs and Webpack

Maybe it was when I switched to bundling with webpack, but initially when I started my project I was able to bundle my js into a bundle.js file but still have access to the files in the browser debugging tool. Now all I see in the browser in my js folder is bundle.js

Using webpack how do I get back to being able to see all my Javascript files in the browser debugger so I can do stuff like insert breakpoints?

like image 261
Nick Pineda Avatar asked Sep 28 '15 15:09

Nick Pineda


People also ask

How do I debug a JavaScript bundle in Chrome?

Open developer tools in chrome by pressing F12 /Ctrl + Shift + I/ right-click anywhere inside the web page and select Inspect/Inspect Element which will be mostly the last option. Go to Sources tab in developer tools and open any minified JS which you want to debug as shown in the image.

How do I debug a Webpack bundle file?

Click the "inspect" link under each script to open a dedicated debugger or the Open dedicated DevTools for Node link for a session that will connect automatically. You can also check out the NiM extension, a handy Chrome plugin that will automatically open a DevTools tab every time you --inspect a script.

How do I debug a TSX file in Chrome?

Browser DebugPut a breakpoint inside the label function. Then, re-run the JavaScript Debug configuration you just made, but this time, click the Debug button. Chrome should pop up. Reload the URL and focus shifts to the IDE, with execution stopped on the line of the breakpoint.


1 Answers

After a long time of pointlessly using a bunch of print statements I finally went back and figured out how to do this.

Here is how you get your ability to use breakpoints again after you bundle:

1)

Go to your webpack.config.js file and set devtools from "true" to "source-map" or one of the other options that @MichelleTilley explained in her answer.

webpack.config.js(here is an example)

module.exports = {   entry: "./js/app.js",   output: {     filename: "js/bundle.js"   },   debug: true,   devtool: "#eval-source-map",   module: {     loaders: [       {         test: /\.jsx?$/,         exclude: /(node_modules|bower_components)/,         loader: 'babel'       }     ]   } }; 

2)

Also like @MichelleTilley explained in her answer you may need to enable the devtools options in the Chrome.

3)

After this the when you go to debug you will have to look for a new folder just named "." that is super hard to notice!

Thanks to the Stackoverflow answer below with the posted images I finally found where that folder was.

Configure webpack to allow browser debugging

like image 107
Nick Pineda Avatar answered Oct 26 '22 23:10

Nick Pineda