简体   繁体   中英

Running into 'TypeError: args.cb is not a function' Error when using gulp

I am relatively new to using Gulp for my workflow. Below is my gulpfile.js. I have tried to debug myself and using some hints from another BrowserStack question, but I cant figure it out.

When I save a.php file it reloads the browser, but errors. When I update a scss file, then it completely sass successfully.

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'));
});

This is the error I am receiving:

[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)

I cannot figure out where the error is. Any help would be greatly appreciated.

From the stack trace, I could infer that the error is originating from done that is being passed to your sync function as an argument. That done isn't a function but is being called like one and that's probably why you are getting args.cb is not a function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM