Gulp imagemin dest.on不是函数错误

时间:2016-07-07 19:38:37

标签: javascript node.js console gulp imagemin

我正在尝试使用imagemin缩小图像,但它会出错。 无法理解我做错了什么。

这是我的gulpfile

'use strict';

var gulp = require('gulp');
var imagemin = require('imagemin');
var clean = require('gulp-clean');

gulp.task('img', function () {
  return gulp.src('src/img/**')
    .pipe(imagemin())
    .pipe(gulp.dest('build/img'));
});

gulp.task('clean', function() {
  console.log('-----------удаляю build');
  return gulp.src('build', {read: false})
    .pipe(clean());
});

来自控制台的错误消息

$ gulp img
(node:14312) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
[22:10:20] Using gulpfile Z:\a\gulpfile.js
[22:10:20] Starting 'img'...
[22:10:20] 'img' errored after 26 ms
[22:10:20] TypeError: dest.on is not a function
    at DestroyableTransform.Readable.pipe (Z:\a\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:516:8)
    at Gulp.<anonymous> (Z:\a\gulpfile.js:9:6)
    at module.exports (Z:\a\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (Z:\a\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (Z:\a\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (Z:\a\node_modules\orchestrator\index.js:134:8)
    at C:\Users\Artur\AppData\Roaming\npm\node_modules\gulp\node_modules\gulp-cli\lib\versioned\^3.7.0\index.js:46:20
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
    at Function.Module.runMain (module.js:577:11)

1 个答案:

答案 0 :(得分:7)

当您尝试pipe()不是gulp.dest()的流时,会抛出此错误。

我在您的代码var imagemin = require('imagemin');中看到了 - 您确定不打算写var imagemin = require('gulp-imagemin');吗? imagemin 不会返回正确的gulp流,但 gulp-imagemin 会。