gruntjs / grunt-contrib-imagemin

Minify PNG, JPG, GIF and SVG images.
https://gruntjs.com
MIT License
1.21k stars 175 forks source link

stream.on is not a function #359

Closed bitstarr closed 8 years ago

bitstarr commented 8 years ago

I recently initialized my project and npm got the latest version of grunt-contrib-imagemin.

I get the following error:

Running "imagemin:project" (imagemin) task Fatal error: stream.on is not a function

I don't know where to dig for a more exact error description. Can somebody please help?

package.json

    "devDependencies": {
        "grunt": "*",
        "bower": "*",
        "load-grunt-tasks": "*",
        "grunt-contrib-watch": "*",
        "grunt-contrib-csslint": "*",
        "grunt-contrib-jshint": "*",
        "grunt-jsonlint": "*",
        "grunt-contrib-concat": "*",
        "grunt-contrib-uglify": "*",
        "grunt-shell": "*",
        "grunt-newer": "*",
        "grunt-contrib-imagemin": "*",
        "imagemin-mozjpeg": "*",
        "grunt-svgstore": "*",
        "grunt-svgmin": "*",
        "less": "*",
        "grunt-contrib-less": "*",
        "grunt-lesslint": "*",
        "grunt-autoprefixer": "*",
        "grunt-contrib-cssmin": "*",
        "grunt-browser-sync": "*"
    }

grunt task:

imagemin: {
    project: {
        options: {
            use: [mozjpeg()]
        },
        files: [{
            expand: true,
            cwd: '<%=project.img%>',
            src: ['**/*.{png,jpg,gif}'],
            dest: '<%=project.dist.img%>'
        }]
    }
},
damy90 commented 8 years ago

I had the same problem today. Try downgrading mozjpeg to version 5.1.0

kevva commented 8 years ago

Yup, grunt-contrib-imagemin doesn't support the new plugin API in imagemin and probably won't for a foreseeable future since grunt still supports deprecated versions of node.

MagazineduWebdesign commented 8 years ago

@kevva Thanks for your reply. With your expertise, do you think we can work around this issue to continue using grunt-contrib-imagemin ?

kevva commented 8 years ago

@MagazineduWebdesign, if you get stream.on is not a function, try using the previous version of the plugin like @damy90 suggested.

MagazineduWebdesign commented 8 years ago

@kevva Thanks for your reply. Nevertheless, I didn't manage the issue. I switched momentarily to grunt-image :disappointed:

zhangbg commented 8 years ago

I have the same problem too, and my mozjpeg's version is 6.0.0. I can't solve it. My solution is not using the mozjpeg plugin in imagemin task.

bitstarr commented 8 years ago

As suggested above downgrading "imagemin-mozjpeg" to 5.1.0 brings back functionality. Nonetheless i hope the issue will get fixed soon, so we can use the latest version.

arieluya commented 8 years ago

Got this error :


Warning: spawn /www/node_modules/grunt-image/node_modules/jpeg-recompress-bin/vendor/jpeg-recompress EMFILE Use --force to continue.
Error: spawn /www/node_modules/grunt-image/node_modules/jpeg-recompress-bin/vendor/jpeg-recompress EMFILE
    at exports._errnoException (util.js:873:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
    at onErrorNT (internal/child_process.js:344:16)
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickCallback (node.js:356:17)

  "devDependencies": {
    "grunt": "~0.4.5",
    "grunt-contrib-concat": "^1.0.1",
    "grunt-contrib-cssmin": "^0.12.3",
    "grunt-contrib-imagemin": "^1.0.1",
    "grunt-contrib-jshint": "~0.10.0",
    "grunt-contrib-less": "*",
    "grunt-contrib-nodeunit": "~0.4.1",
    "grunt-contrib-uglify": "~0.5.0",
    "grunt-contrib-watch": "*",
    "grunt-image": "^2.1.0",
    "grunt-notify": "^0.4.5",
    "gulp": "^3.9.1",
    "gulp-imagemin": "^3.0.2",
    "imagemin-mozjpeg": "^5.1.0",
    "imagemin-pngquant": "^4.1.0"
  },
jieyou commented 8 years ago

I've got the same problem . I updated grunt to version "~1.0.0" and resolved.

valnub commented 8 years ago

Downgrading mozjpeg to 5.1.0 also fixed the issue for me, thanks!

hipervee commented 8 years ago

I recently switched to mac and started my development there. imagemin task is failing on mac with the same issue but not on windows

Can anybody help me?