运行到'TypeError:args.cb不是函数“使用gulp时出错

gmxoilav  于 2022-12-08  发布在  Gulp
关注(0)|答案(1)|浏览(169)

我对在工作流中使用Gulp还比较陌生。下面是我的gulpfile.js。我试着调试自己,并使用了另一个BrowserStack问题中的一些提示,但我无法弄清楚。
当我保存一个.php文件时,它会重新加载浏览器,但会出错。当我更新一个scss文件时,它会完全成功。

const gulp = require( 'gulp' );
const sourcemaps = require( 'gulp-sourcemaps' );
const sass = require('gulp-sass');
const csso = require('gulp-csso');
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync').create();
 
sass.compiler = require('node-sass');

// Create browsersyn function
function sync(done) {
  browserSync.init({
    files: './**/*.php',
    // Changegit
    proxy: 'http://localhost/jacks-bistro'
  });
  done();
}

// Create sass and sourcemaps function
function sassy() {
  return gulp.src('./assets/*.scss')
    .pipe( sourcemaps.init() )
    .pipe(sass().on('error', sass.logError))
    .pipe( autoprefixer() )
    .pipe(csso())
    .pipe( sourcemaps.write( './' ) )
    .pipe(gulp.dest('./'))
    .pipe(browserSync.stream());
};

// Create tasks for functions(probably not needed)
gulp.task( "sass", sassy );
gulp.task( "sync", sync );

// Create watch task
gulp.task( 'watch', function () {
  gulp.watch('./assets/*.scss', gulp.series('sass'));
  gulp.watch('./**/*.php', gulp.series('sync'));
});

这是我收到的错误:

[23:07:06] 'sync' errored after 815 μs
[23:07:06] TypeError: args.cb is not a function
    at Object.init (/Applications/XAMPP/xamppfiles/htdocs/jacks-bistro/wp-content/themes/jb_ewm/node_modules/browser-sync/dist/public/init.js:21:25)
    at sync (/Applications/XAMPP/xamppfiles/htdocs/jacks-bistro/wp-content/themes/jb_ewm/gulpfile.js:12:15)
    at sync (/Applications/XAMPP/xamppfiles/htdocs/jacks-bistro/wp-content/themes/jb_ewm/node_modules/undertaker/lib/set-task.js:13:15)
    at bound (domain.js:430:14)
    at runBound (domain.js:443:12)
    at asyncRunner (/Applications/XAMPP/xamppfiles/htdocs/jacks-bistro/wp-content/themes/jb_ewm/node_modules/async-done/index.js:55:18)
    at processTicksAndRejections (internal/process/task_queues.js:75:11)

我找不出错误在哪里。任何帮助都将不胜感激。

hvvq6cgz

hvvq6cgz1#

从堆栈跟踪中,我可以推断错误源自done,它作为参数传递给sync函数。done不是函数,但被像函数一样调用,这可能就是为什么你得到的args.cb不是函数。

相关问题