Search code examples
node.jsdebuggingintellij-ideagulpbreakpoints

Using gulp instead of nodejs in IntelliJ ignores breakpoints


I have inherited a project running gulp+nodejs. I am trying to use IntelliJ in Windows as my IDE.

If I set my runtime configuration to use "node.js" as its type, I have no problem hitting breakpoints and debugging. However, if I use "gulp.js" as the run type, breakpoints are ignored (and I can essentially never debug). I also tried using Node.js configuration and setting the JS file to node_modules/gulp/bin/gulp.js instead of server/run.js . This seems to have the exact same problem.

Any thoughts on how I could fix this?


Solution

  • Gulp run configuration is not supposed to be used for Node application debugging - it was designed to run/debug Gulp tasks. To debug your Node.js application, you need to create a Node.js Run configuration and specify the .js file generated by Gulp build as a file to debug.

    If you still prefer using Gulp to start your server, make sure that it is started with -debug-brk and then use Node.js Remote run configuration to attach the debugger.

    Like:

    var gulp = require('gulp');
    var exec = require('child_process').exec;
    
    gulp.task('server', function (cb) {
      exec('node --debug-brk=5858 app.js', function (err, stdout, stderr) {
    ...
    

    run your server task, then create Node.js Remote run configuration and hit Debug

    enter image description here