启动Gulp时发生错误:TypeError:dest.on不是函数

时间:2018-09-21 19:39:45

标签: gulp

我开始使用gulp.js为我的个人网站创建自己的工作环境,直到偶然发现了我似乎无法解决的错误。

这是我的代码: (请注意,我很确定错误是在我的“ sassCompile”任务中造成的)

/**
 * Initialize all gulp plugins
 */
var gulp = require('gulp');
var sass = require('gulp-sass');
var pug = require('gulp-pug');
var browserSync = require('browser-sync').create();
var autoPrefixer = require('autoprefixer');
var plumber = require('gulp-plumber');
var sourceMaps = require('gulp-sourcemaps');

/**
 * Launch browsersync
 */

gulp.task('sync', ['sassCompile', 'pugCompile'], function(){
    browserSync.init({
        server: {
            baseDir: './'
        }
    });
});

/**
 * Compile sass and css files into css so the browser can read them.
 */

 gulp.task('sassCompile', function() {
     gulp.src('src/sass/*.scss')
     .pipe(plumber())
     .pipe(sourceMaps.init())
     .pipe(sass({
         errorLogToConsole: true,
         outputStyle: 'compressed'
     }))
     .on('error', console.error.bind(console))
     .pipe(autoPrefixer('last 2 versions', {cascade: true}))
     .pipe(gulp.dest('./css'))
     .pipe(browserSync.reload({stream: true}));
 });

 /**
  * Compile pug files into html so the browser can read them.
  */

  gulp.task('pugCompile', function() {
      gulp.src('src/pugfiles/*.pug')
      .pipe(plumber())
      .pipe(pug())
      .pipe(gulp.dest('./HTML'))
  });

这将导致此错误:

TypeError: dest.on is not a function
    at DestroyableTransform.Readable.pipe (C:\Users\lucas\Desktop\Portfolio\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:564:8)
    at DestroyableTransform.pipe2 (C:\Users\lucas\Desktop\Portfolio\node_modules\gulp-plumber\index.js:72:14)
    at Gulp.<anonymous> (C:\Users\lucas\Desktop\Portfolio\gulpfile.js:37:7)
    at module.exports (C:\Users\lucas\Desktop\Portfolio\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\Users\lucas\Desktop\Portfolio\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\Users\lucas\Desktop\Portfolio\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (C:\Users\lucas\Desktop\Portfolio\node_modules\orchestrator\index.js:134:8)
    at C:\Users\lucas\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickCallback (internal/process/next_tick.js:181:9)

我的目录: Directory

如果需要其他任何信息,请确保提供。

1 个答案:

答案 0 :(得分:0)

我认为这是因为 autoprefixer 不返回流。

尝试改用 gulp-autoprefixer

var autoprefixer = require('gulp-autoprefixer');

...并将其传递给选项的对象:

// ...
.pipe(autoprefixer({
  browsers: ['last 2 versions'],
  cascade: true
}))

https://www.npmjs.com/package/gulp-autoprefixer