grunt watch livereload Fatal error: Port 35279 is already in use by another process

时光毁灭记忆、已成空白 提交于 2019-12-04 19:09:39

问题


I'm trying to use livereload with watch. I keep getting the message "Fatal error: Port 35279 is already in use by another process" . I've changed the port for livereload but then nothing reloads.

module.exports = function(grunt) {
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    compass: {
      dist: {
        options: {
          cssDir: 'stylesheets',
          sassDir: 'stylesheets/sass/',
          imagesDir: 'images',
          javascriptsDir: 'scripts',
          require: ['sass-globbing','modular-scale'],
          force: true
        }
      }
    },
    cssmin: {
      minify: {
        expand: true,
        cwd: 'stylesheets',
        src: ['*.css', '!*.min.css'],
        dest: 'stylesheets',
        ext: '.min.css'
      }
    },
    watch: {
        options: {
            livereload: true
        },
        sass: {
            files: 'stylesheets/sass/*.scss',
            tasks: ['compass']
        },
        css: {
            files: 'stylesheets/*.css',
            tasks: ['cssmin']
        },
        html: {
            files: ['index.html','**/*.css']
        }
    }
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.registerTask('default',['compass','watch']);

}


回答1:


Add

 <script src="//localhost:1337/livereload.js"></script>

to the page you want livereload on. 1337 being the port you set it to in the grunt file.

options: {
        livereload: 1337
},



回答2:


You can manually shutdown the livereload server in a bash/terminal window like so:

curl localhost:35279/kill

More info here: https://github.com/mklabs/tiny-lr




回答3:


Are you using the Sublime Text and the LiveReload package? It's been known to cause this issue. If so, disable or uninstall the package in Sublime Text.




回答4:


I use grunt on a vagrant VM so i need grunt to run on port 80, first i'll stop apache and start grunt serve and it works just fine.

Sometimes, however, grunt for some reason won't release the port after being stopped. For example: i usually stop grunt to edit the Gruntfile.js and start it again, but sometimes it won't start and will complain about someone using the por 80.

The only solution that has worked for me is to restart your shell session and try again.

I use ZSH and i noticed that after grunt breaks if i try to exit the shell ZSH complains about 'pending jobs', but if i exit anyways and restart the session and try grunt serve again it will work.




回答5:


If you want to terminate the process using the port, you can do the following:

$ lsof -n -i4TCP:35729
COMMAND   PID      USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node    15723  testuser   24u  IPv6 0x71823b3990749ea5      0t0  TCP *:35729 (LISTEN)

Now you have the PID of the process that's listening on the port you're trying to access, so you can kill this with

$ kill -9 15723

and now running grunt should work just fine :)



来源:https://stackoverflow.com/questions/19268136/grunt-watch-livereload-fatal-error-port-35279-is-already-in-use-by-another-proc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!