Grunt Watch Fatal error: listen EACCES and liverel

2019-04-14 20:10发布

PC Specs: Windows 7 Enterprise x64

I'm running grunt.js on a project and recently started receiving an error when attempting to run 'grunt watch'.

Grunt worked fine yesterday but today I started seeing:

Running "watch" task Waiting...Fatal error: listen EACCES

I read another question here: Cloud 9 and Grunt.js

that lead me to remove 'options: {livereload: true}' from Gruntfile.js

running watch again works as intended. Is there a way to reconfigure grunt or livereload to get livereload working with Grunt again?

Also, just running the command 'grunt' runs all of the tasks without errors.

Thanks.

Edit: Gruntfile.js follows:

module.exports = function(grunt) {
    grunt.initConfig({
        jshint: {
            all: ['js/src/*.js']
        },
        uglify: {
            options: {
                mangle: {
                    except: ['jQuery']
                },
                preserveComments: 'none'
            },
            'js/main.min.js': ['js/tmp/debug.js']
        },
        compass: {
            options: {
                config: '.compass.rb',
                sassDir: 'sass',
                cssDir: '.'
            },
            my_target: {
            }
        },
        cmq: {
            my_target: {
                files: { 'tmp': ['style.css'] }
            }
        },
        cssmin: {
            minify: {
                keepSpecialComments: 0,
                expand: true,
                cwd: 'tmp/',
                src: ['style.css'],
                dest: '.',
                ext: '.css'
            }
        },
        imagemin: {
            png: {
                options: {
                    optimizationLevel: 7
                },
                files: [{
                    expand: true,
                    cwd: 'img',
                    src: ['**/*.png'],
                    dest: 'img',
                    ext: '.min.png'
                }]
            },
            jpg: {
                options: {
                    progressive: true
                },
                files: [{
                    expand: true,
                    cwd: 'img',
                    src: ['**/*.jpg'],
                    dest: 'img',
                    ext: '.min.jpg'
                }]
            },
            gif: {
                options: {
                    progressive: true
                },
                files: [{
                    expand: true,
                    cwd: 'img',
                    src: ['**/*.gif'],
                    dest: 'img',
                    ext: '.min.gif'
                }]
            }
        },
        clean: ["tmp"],
        watch: {
            scripts: {
                files: 'js/src/*.js',
                tasks: ['jshint', 'concat', 'uglify', 'clean'],
                options: { livereload: true }
            },
            css: {
                files: 'sass/*.scss',
                tasks: ['compass', 'cmq', 'cssmin', 'clean'],
                options: { livereload: true }
            }
        },
            concat: {
            debug: {
                src: ['js/src/**/*.js'],
                dest: 'js/tmp/debug.js'
            }
        },
    });

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-compass');
    grunt.loadNpmTasks('grunt-combine-media-queries');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-imagemin');

    grunt.registerTask('default', ['jshint', 'concat', 'uglify', 'compass', 'cmq', 'cssmin', 'clean']);
}

3条回答
Emotional °昔
2楼-- · 2019-04-14 20:37

In my never ending brilliance, I had fireapp running on a separate project. fireapp has the option to enable livereload.

Inititally when I asked the question it was because I had two calls within Gruntfile.js as Kyle correctly surmised. This solution didn't work for me because I still had two separate versions of livereload running with fireapp watching a separate project.

Kyle's second option did the trick.

Thanks!

查看更多
再贱就再见
3楼-- · 2019-04-14 20:43

It appears you have 2 live reload servers configured to spawn on the same default port. Instead of specifying livereload: true twice in your watch config, just configure it once:

watch: {
    options: { livereload: true },
    scripts: {
        files: 'js/src/*.js',
        tasks: ['jshint', 'concat', 'uglify', 'clean'],
    },
    css: {
        files: 'sass/*.scss',
        tasks: ['compass', 'cmq', 'cssmin', 'clean'],
    },
},

Then it will only spawn 1 live reload server.

Another option is to create a watch target specifically for live reload and watch your destination files:

watch: {
    scripts: {
        files: 'js/src/*.js',
        tasks: ['jshint', 'concat', 'uglify', 'clean'],
    },
    css: {
        files: 'sass/*.scss',
        tasks: ['compass', 'cmq', 'cssmin', 'clean'],
    },
    lr: {
        options: { livereload: true },
        files: ['js/*.js', 'css/*.css'],
    },
},
查看更多
劳资没心,怎么记你
4楼-- · 2019-04-14 20:59

You don't have permission to make some changes .

  1. Go to project folder.
  2. Open terminal in project folder & execute following command .

    sudo chmod -R a+rwx ./
    
查看更多
登录 后发表回答