Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: dest.on is not a function #142

Closed
Extarys opened this issue Feb 16, 2019 · 6 comments
Closed

TypeError: dest.on is not a function #142

Extarys opened this issue Feb 16, 2019 · 6 comments
Labels

Comments

@Extarys
Copy link

Extarys commented Feb 16, 2019

I am having trouble using this module.

Script:

var path = require('path')
var gulp = require('gulp')
var imagemin = require('imagemin')

var merge2 = require('merge-stream');
var merge = require('merge2');

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

var spritesmith = require('gulp.spritesmith');
var spritesmash = require('gulp-spritesmash');
var pngquant = require('imagemin-pngquant');

var rename = require("gulp-rename");
var source = "./testorig/"
var dest = "./test/"

gulp.task('sprites', function () {
    var files = gulp.src(source+'/*.png')

    // Short version:

    var spriteData = files
        .pipe(spritesmith({
            imgName: 'sprite.png',
            cssName: 'sprite.css'
        }));

    var buffer = require('vinyl-buffer');
    var imgStream = spriteData.img
        .pipe(buffer())
        .pipe(imagemin({
            progressive: true,
            interlaced: true,
            optimizationLevel: 7,
            svgoPlugins: [{
                removeViewBox: false
            }, {
                removeUselessStrokeAndFill: false
            }],
            plugins: [
                pngquant({
                    quality: [70,90],
                    speed: 1
                })
            ]
        }))
        .pipe(gulp.dest(dest));
});

Trace:

[08:08:50] Starting 'sprites'...
[08:08:50] 'sprites' errored after 11 ms
[08:08:50] TypeError: dest.on is not a function
    at DestroyableTransform.Readable.pipe (/srv/test/node_modules/readable-stream/lib/_stream_readable.js:564:8)
    at /srv/test/gulpfile.js:64:10
    at taskWrapper (/srv/test/node_modules/undertaker/lib/set-task.js:13:15)
    at bound (domain.js:301:14)
    at runBound (domain.js:314:12)
    at asyncRunner (/srv/test/node_modules/async-done/index.js:55:18)
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickCallback (internal/process/next_tick.js:181:9)

Versions:

Nodejs: 8.15.0
  "dependencies": {
    "gulp": "^4.0.0",
    "gulp-gm": "^0.0.9",
    "gulp-rename": "^1.4.0",
    "gulp-spritesmash": "^1.1.1",
    "gulp.spritesmith": "^6.9.0",
    "imagemin": "^6.1.0",
    "imagemin-pngquant": "^7.0.0",
    "merge-stream": "^1.0.1",
    "merge2": "^1.2.3",
    "vinyl-buffer": "^1.0.1"
  }
@twolfson
Copy link
Owner

There's a lot going on in this script. Can you remove anything not related to gulp or gulp.spritesmith to verify the dest.on isn't arising from another package or its syntax?

I believe the following version should do that:

var gulp = require('gulp')
var spritesmith = require('gulp.spritesmith');
var source = "./testorig/"
var dest = "./test/"

gulp.task('sprites', function () {
    var files = gulp.src(source+'/*.png')

    // Short version:

    var spriteData = files
        .pipe(spritesmith({
            imgName: 'sprite.png',
            cssName: 'sprite.css'
        }));

    // We need to return our stream to `gulp` so it knows when the task is done
    return spriteData.pipe(gulp.dest(dest));
});

@Extarys
Copy link
Author

Extarys commented Feb 16, 2019

Thanks for your reply.
Well not that much, it's the recommended way on the readme, to use the buffer() thing, but I get an error.

The image and the css is saved properly if I don't try to pass it to imagemin.

    var imgStream = spriteData.img
        .pipe(buffer())
        .pipe(imagemin({ // < ----- Error line
            progressive: true,
            interlaced: true,
            optimizationLevel: 7,
            svgoPlugins: [{
                removeViewBox: false
            }, {
                removeUselessStrokeAndFill: false
            }],
            plugins: [

                pngquant({
                    quality: [70,90],
                    speed: 1
                })
            ]
        }))
        .pipe(gulp.dest(dest));

@twolfson
Copy link
Owner

twolfson commented Feb 17, 2019 via email

@Extarys
Copy link
Author

Extarys commented Feb 17, 2019

I checked but they releases 1.0.1 a year ago... and the syntax seems fine to me. If you have a moment could you check to confirm this?

@twolfson
Copy link
Owner

Ah, I see the issue. You're using imagemin instead of gulp-imagemin:

var imagemin = require('imagemin');
// Should be
var imagemin = require('gulp-imagemin');

For reference, we do provide the README examples in docs/gulpfile.js. I was able to verify gulp sprite-pipeline is still working:

https://github.com/twolfson/gulp.spritesmith/blob/6.9.0/docs/gulpfile.js#L23-L44

@Extarys
Copy link
Author

Extarys commented Feb 18, 2019

Oh damn! I'm very sorry, I didn't notice that at all in all the time I spent trying to make it work.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants