WebStorm / grunt调试运行抛出EADDRINUSE错误

时间:2016-05-18 14:47:34

标签: node.js gruntjs webstorm

我有一个使用WebStorm IDE开发的Node / Angular应用程序。我可以通过WebStorm( Shift + F10 )运行应用程序。但是,每当我尝试在调试模式下运行时,我都会收到EADDRINUSE错误:

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

这是我的gruntfile.js - 就像我说的,WebStorm构建并运行得很好,直到我尝试在调试模式下运行它,它会抛出错误:

'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']);
};

1 个答案:

答案 0 :(得分:7)

问题是由Grunt产生子任务的方式引起的。默认情况下,grunt.util.spawn()继承主进程参数并使用与主进程相同的选项启动子进程(--debug-brk = 52387),因此子进程在与主进程相同的调试端口上启动,导致EADDRINUSE。请参阅https://github.com/gruntjs/grunt/issues/1420

作为一种解决方法,尝试将process.execArgv = [];添加到Gruntfile.js的顶部 - 它应该有帮助