执行gulp watch任务报错:TypeError: this.pingIntervalTimer.refresh is not a function
解决Gulp Watch启动BrowserSync后报错TypeError: this.pingIntervalTimer.refresh is not a function
问题描述
执行npm update --save更新项目依赖后,运行gulp watch时服务器能正常启动,但500-600ms后控制台抛出错误:TypeError: this.pingIntervalTimer.refresh is not a function。使用的Gulpfile代码如下:
var gulp = require('gulp'), watch = require('gulp-watch'), browserSync = require('browser-sync').create(); gulp.task('serve', function() { browserSync.init({ server: { baseDir: "src" }, notify: false }); }); gulp.task('watch', ['serve'], function() { gulp.watch('./src/*.html', browserSync.reload); });
解决方案
- 降级BrowserSync到兼容旧版Gulp的稳定版本,比如2.27.10:
npm install browser-sync@2.27.10 --save-dev - 执行完上述命令后重新运行
gulp watch,错误即可消失。
原因说明
该错误源于最新版BrowserSync内部API变更,移除了pingIntervalTimer.refresh方法,而你的Gulp版本(从代码中的gulp.task语法判断为Gulp 3.x)与新版BrowserSync存在兼容性冲突。降级到指定的稳定版本后,API匹配即可恢复正常运行。
内容的提问来源于stack exchange,提问作者windeAlps
相关产品推荐
相关产品推荐

