Gulp / Node.js错误:连接ECONNREFUSED

我目前正在使用WAMP运行本地服务器,并且正在尝试设置Gulp.js. 这里是我的gulpfile的内容:

var gulp = require('gulp'), sass = require('gulp-ruby-sass'), autoprefixer = require('gulp-autoprefixer'), minifycss = require('gulp-minify-css'), minifyhtml = require('gulp-minify-html'), jshint = require('gulp-jshint'), uglify = require('gulp-uglify'), imagemin = require('gulp-imagemin'), rename = require('gulp-rename'), clean = require('gulp-clean'), concat = require('gulp-concat'), notify = require('gulp-notify'), cache = require('gulp-cache'), livereload = require('gulp-livereload'), lr = require('tiny-lr'), server = lr(); gulp.task('styles', function() { gulp.src('src/styles/main.scss') .pipe(sass({ style: 'expanded' })) .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4')) .pipe(gulp.dest('dist/assets/css')) .pipe(rename({suffix: '.min'})) .pipe(minifycss()) .pipe(gulp.dest('dist/css')) .pipe(livereload(server)) .pipe(notify({ message: 'Styles task complete' })); }); gulp.task('html', function() { gulp.src('src/*.php') .pipe(minifyhtml()) .pipe(gulp.dest('dist')) .pipe(livereload(server)) .pipe(notify({ message: 'HTML task complete' })); }); gulp.task('default', function() { gulp.run('html'); }); 

这是我运行gulp时得到的输出:

 [gulp] Using gulpfile C:\wamp\www\SawyerK\gulpfile.js [gulp] Starting 'default'... gulp.run() has been deprecated. Use task dependencies or gulp.watch task trigger ing instead. [gulp] Starting 'html'... [gulp] Finished 'html' after 132 ms [gulp] Finished 'default' after 134 ms [gulp] gulp-notify: [Gulp notification] HTML task complete events.js:72 throw er; // Unhandled 'error' event ^ Error: connect ECONNREFUSED at errnoException (net.js:904:11) at Object.afterConnect [as oncomplete] (net.js:895:19) 

从我发现,这个错误被抛出,因为别的是使用端口节点想要的东西或类似的东西? 但是,我不完全确定这是否正确,我绝对不知道如何解决这个问题。 有什么想法吗? 谢谢!

编辑:我似乎已经缩小到吞咽通知,如果有帮助

我认为问题在于你使用livereload两次,在styles任务和html。 也许最好使用watchcher的livereload:

 gulp.task('watch', function() { var server = livereload(); gulp.watch('build/**').on('change', function(file) { server.changed(file.path); }); }); 

更新:对不起,错了=)这是一个伟大的文章,第二部分,显示如何使用手表任务。 链接要使用livereload,需要使用listen方法启动服务器。

你在Windows上偶然吗? 我的开发团队遇到了这个问题,它看起来在Windows 7 + gulp-notify要求低吼。 :/

你可以在gulpforwindows.com下载exe,我相信你也需要重启你的机器。

https://github.com/mikaelbr/gulp-notify/issues/30

https://github.com/mikaelbr/gulp-notify#requirements