You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 07:31:07