DShultz
DShultz

Reputation: 4541

WebStorm / grunt debug run throwing EADDRINUSE error

I have a Node/Angular app, developed using the WebStorm IDE. I can run the application fine via WebStorm (Shift + F10). However, any time I try to run in debug mode, I am receiving the EADDRINUSE error:

Running "concurrent:default" (concurrent) task
Verifying property concurrent.default exists in config...OK
Files: [no src] -> default
Options: limit=10, logConcurrentOutput
Error: listen EADDRINUSE :::52387

Here is my gruntfile.js - like I said, WebStorm builds and runs it just fine, until I try to run it in debug mode, where it throws the error:

'use strict';

var fs = require('fs');

module.exports = function(grunt) {
// Unified Watch Object
var watchFiles = {
    serverViews: ['app/views/**/*.*'],
    serverJS: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js', '!app/tests/'],
    clientViews: ['public/modules/**/views/**/*.html'],
    sass: ['public/css/*.scss'],
    clientJS: ['public/js/*.js', 'public/modules/**/*.js'],
    clientCSS: ['public/modules/**/*.css'],
    mochaTests: ['app/tests/**/*.js']
};

// Project Configuration
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    watch: {
        serverViews: {
            files: watchFiles.serverViews,
            options: {
                livereload: true
            }
        },
        serverJS: {
            files: watchFiles.serverJS,
            tasks: ['jshint'],
            options: {
                livereload: true
            }
        },
        clientViews: {
            files: watchFiles.clientViews,
            options: {
                livereload: true
            }
        },
        clientJS: {
            files: watchFiles.clientJS,
            tasks: ['jshint'],
            options: {
                livereload: true
            }
        },
        clientCSS: {
            files: watchFiles.clientCSS,
            tasks: ['csslint'],
            options: {
                livereload: true
            }
        },
        sass: {
            files: watchFiles.sass,
            tasks: ['sass:dev'],
            options: {
                livereload: true
            }
        },
        mochaTests: {
            files: watchFiles.mochaTests,
            tasks: ['test:server'],
        }
    },
    jshint: {
        all: {
            src: watchFiles.clientJS.concat(watchFiles.serverJS),
            options: {
                jshintrc: true
            }
        }
    },
    csslint: {
        options: {
            csslintrc: '.csslintrc'
        },
        all: {
            src: watchFiles.clientCSS
        }
    },
    uglify: {
        production: {
            options: {
                mangle: false
            },
            files: {
                'public/dist/application.min.js': 'public/dist/application.js'
            }
        }
    },
    cssmin: {
        combine: {
            files: {
                'public/dist/application.min.css': '<%= applicationCSSFiles %>'
            }
        }
    },
    nodemon: {
        dev: {
            script: 'server.js',
            options: {
                nodeArgs: ['--debug'],
                ext: 'js,html',
                watch: watchFiles.serverViews.concat(watchFiles.serverJS)
            }
        }
    },
    'node-inspector': {
        custom: {
            options: {
                'web-port': 1337,
                'web-host': 'localhost',
                'debug-port': 5858,
                'save-live-edit': true,
                'no-preload': true,
                'stack-trace-limit': 50,
                'hidden': []
            }
        }
    },
    concurrent: {
        default: ['nodemon', 'watch'],
        debug: ['nodemon', 'watch', 'node-inspector'],
        options: {
            logConcurrentOutput: true,
            limit: 10
        }
    },
    env: {
        test: {
            NODE_ENV: 'test'
        },
        secure: {
            NODE_ENV: 'secure'
        },
        development: {
            NODE_ENV: 'development'
        }
    },
    mochaTest: {
        src: watchFiles.mochaTests,
        options: {
            reporter: 'spec',
            require: 'server.js'
        }
    },
    karma: {
        unit: {
            configFile: 'karma.conf.js'
        }
    },
    sass: {
      dev: {
        files: {
          'public/css/style.css': 'public/css/*.scss'
        }
      }
    },
    copy: {
        localConfig: {
            src: 'config/env/local.example.js',
            dest: 'config/env/local.js',
            filter: function() {
                return !fs.existsSync('config/env/local.js');
            }
        }
    }
});

// Load NPM tasks
require('load-grunt-tasks')(grunt);

// Making grunt default to force in order not to break the project.
grunt.option('force', true);

// A Task for loading the configuration object
grunt.task.registerTask('loadConfig', 'Task that loads the config into a grunt option.', function() {
    var init = require('./config/init')();
    var config = require('./config/config');

    grunt.config.set('applicationJavaScriptFiles', config.assets.js);
    grunt.config.set('applicationCSSFiles', config.assets.css);
});

//Sass task
grunt.registerTask('default', ['lint', 'sass:dev', 'concurrent:default']);

// Debug task.
grunt.registerTask('debug', ['lint', 'copy:localConfig', 'concurrent:debug']);

// Secure task(s).
grunt.registerTask('secure', ['env:secure', 'lint', 'copy:localConfig', 'concurrent:default']);

// Lint task(s).
grunt.registerTask('lint', ['jshint', 'csslint']);

// Build task(s).
grunt.registerTask('build', ['lint', 'loadConfig', 'ngAnnotate', 'uglify', 'cssmin']);

// Test task.
grunt.registerTask('test', ['copy:localConfig', 'test:server', 'test:client']);
grunt.registerTask('test:server', ['env:test', 'mochaTest']);
grunt.registerTask('test:client', ['env:test', 'karma:unit']);
};

Upvotes: 3

Views: 897

Answers (1)

lena
lena

Reputation: 93728

The problem is caused by the way Grunt spawns child tasks. By default, grunt.util.spawn() inherits main process arguments and starts child process with same options as the main process (--debug-brk=52387), so child process is started on the same debug port as the main process, causing EADDRINUSE. See https://github.com/gruntjs/grunt/issues/1420.

As a workaround, try adding process.execArgv = []; to the top of Gruntfile.js - it should help

Upvotes: 9

Related Questions