浏览器同步TypeError args.cb不是一个函数 [英] Browser-sync TypeError args.cb is not a function
问题描述
我在gulp任务中使用浏览器同步,例如:
gulp.task('gulp-task', function(){
browserSync.init({
server:{
baseDir:'app'
}
})
//任务的其余部分
});
我在gulp watch中使用这个gulp任务(例如) app / ** / *。html
like:
gulp.task('watch',function() {
gulp.watch('app / ** / *。html',['gulp-task']);
});
首次在html文件中更改一切正常,但对于下次更改,我会收到错误:
TypeError:args.cbn不是函数...
家伙们说要安装最新版本的浏览器 - 请同步以下命令:
npm install browser-sync @ latest --save-dev
并没有帮助。
但我得到同样的错误。有什么不对?
我也遇到了这个问题,并通过从watch任务中的回调中删除括号来解决它。 / p>
尝试将您的手表任务更改为:
gulp.task('手表',函数(){
gulp.watch(['app / ** / *。html'],'gulp-task');
});
或者更好,尝试使用像这样的重载方法:
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'));
});
$ b $ //静态服务器
gulp.task('serve',function(){
browserSync.init({
server:{
baseDir: ./src
}
});
});
$ b gulp.task('watch',function(){
gulp.watch(['src / ** / *。html','src / app / ** / *。 js'],重新加载);
});
I'm using browser-sync in gulp task for example :
gulp.task('gulp-task',function(){
browserSync.init({
server:{
baseDir: 'app'
}
})
//rest of task
});
I use this gulp task in gulp watch for( for example ) app/**/*.html
like :
gulp.task('watch',function(){
gulp.watch('app/**/*.html', ['gulp-task']);
});
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
and it doesn't helped.
but i'm getting the same error. what's wrong?
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');
});
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屋!