浏览器同步 TypeError args.cb 不是函数 [英] Browser-sync TypeError args.cb is not a function
问题描述
例如,我在 gulp 任务中使用浏览器同步:
I'm using browser-sync in gulp task for example :
gulp.task('gulp-task',function(){
browserSync.init({
server:{
baseDir: 'app'
}
})
//rest of task
});
我在 gulp watch 中使用这个 gulp 任务(例如)app/**/*.html
比如:
I use this gulp task in gulp watch for( for example ) app/**/*.html
like :
gulp.task('watch',function(){
gulp.watch('app/**/*.html', ['gulp-task']);
});
第一次更改 html 文件一切正常,但下一次更改时出现错误:TypeError: args.cbn 不是函数...
for first time change in html files everything is ok but for next changes i get error:
TypeError: args.cbn is not a function ...
大家说要使用以下命令安装最新版本的浏览器同步:
guys said to install latest version for browser-sync with command below :
npm install browser-sync@latest --save-dev
它没有帮助.
我遇到了同样的错误.怎么了?
I'm getting the same error. what's wrong?
推荐答案
我也遇到了这个问题,通过在watch任务的回调中去掉括号解决了.
I also ran into this issue and solved it by removing the brackets from the callback in the watch task.
尝试将您的监视任务更改为:
Try changing your watch task to:
gulp.task('watch',function(){
gulp.watch(['app/**/*.html'], 'gulp-task');
});
或者更好的是,尝试使用类似这样的 reload 方法:
Or better yet, try using the reload method with something like this:
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var jshint = require('gulp-jshint');
var watch = require('gulp-watch');
var reload = browserSync.reload;
gulp.task('default', ['jshint', 'serve', 'watch']);
gulp.task('jshint', function() {
return gulp.src('src/app/**/*.js')
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
// Static server
gulp.task('serve', function() {
browserSync.init({
server: {
baseDir: "./src"
}
});
});
gulp.task('watch', function() {
gulp.watch(['src/**/*.html', 'src/app/**/*.js'], reload);
});
这篇关于浏览器同步 TypeError args.cb 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!