5

I am testing the plugin grunt-contrib-imagemin for jpg minify. But it always failed as Running "imagemin:dynamic" (imagemin) task Fatal error: This socket is closed.

Source :
 grunt.initConfig({
        imagemin: { // Task
           dynamic: {                         // Another target
        files: [{
        expand: true,                  // Enable dynamic expansion
        cwd: 'src/',                   // Src matches are relative to this path
        src: ['**/*.{png,jpg,gif}'],   // Actual patterns to match
        dest: 'dist/'                  // Destination path prefix
      }]
    }
        }
    });
AnthonyY
  • 711
  • 12
  • 17
Leslie
  • 51
  • 4

4 Answers4

1

Try re-installing grunt-contrib-imagemin:

npm cache clean
npm install grunt-contrib-imagemin --save-dev
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Eric D.
  • 1,567
  • 1
  • 9
  • 4
1

The Issue:

when doing

npm install

You get the error:

 ? Request to https://raw.github.com/imagemin/jpegtran-bin/3.0.2/vendor/win/x64/jpegtran.exe failed
 ? jpegtran pre-build test failed
 i compiling from source
 × GotError: Request to http://downloads.sourceforge.net/project/libjpeg-turbo/1.4.0/libjpeg-turbo-1.4.0.tar.gz failed
   at ClientRequest.<anonymous> (YourApp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\jpegtr
n-bin\node_modules\bin-build\node_modules\download\node_modules\got\index.js:177:7)
   at ClientRequest.g (events.js:199:16)
   at ClientRequest.emit (events.js:107:17)
   at Socket.socketErrorListener (_http_client.js:271:9)
   at Socket.emit (events.js:107:17)
   at net.js:459:14
   at process._tickCallback (node.js:355:11)
aused By: Error: read ECONNRESET
   at exports._errnoException (util.js:746:11)
   at TCP.onread (net.js:559:26)

 gifsicle@3.0.1 postinstall YourApp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-gifsicle\node_modules\gifsicle
 node lib/install.js

 ? Request to https://raw.github.com/imagemin/gifsicle-bin/3.0.1/vendor/win/x64/gifsicle.exe failed
 ? gifsicle pre-build test failed
 i compiling from source
 × GotError: Request to http://www.lcdf.org/gifsicle/gifsicle-1.87.tar.gz failed
   at ClientRequest.<anonymous> (YourApp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-gifsicle\node_modules\gifsic
e\node_modules\bin-build\node_modules\download\node_modules\got\index.js:177:7)
   at ClientRequest.g (events.js:199:16)
   at ClientRequest.emit (events.js:107:17)
   at Socket.socketErrorListener (_http_client.js:271:9)
   at Socket.emit (events.js:107:17)
   at net.js:459:14
   at process._tickCallback (node.js:355:11)
aused By: Error: read ECONNRESET
   at exports._errnoException (util.js:746:11)
   at TCP.onread (net.js:559:26)

 optipng-bin@3.0.2 postinstall YourApp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-optipng\node_modules\optipng-b
n
 node lib/install.js

 ? Request to https://raw.github.com/imagemin/optipng-bin/3.0.2/vendor/win/optipng.exe failed
 ? optipng pre-build test failed
 i compiling from source
 × GotError: Request to http://downloads.sourceforge.net/project/optipng/OptiPNG/optipng-0.7.5/optipng-0.7.5.tar.gz failed
   at ClientRequest.<anonymous> (YourApp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-optipng\node_modules\optipng
bin\node_modules\bin-build\node_modules\download\node_modules\got\index.js:177:7)
   at ClientRequest.g (events.js:199:16)
   at ClientRequest.emit (events.js:107:17)
   at Socket.socketErrorListener (_http_client.js:271:9)
   at Socket.emit (events.js:107:17)
   at net.js:459:14
   at process._tickCallback (node.js:355:11)
aused By: Error: read ECONNRESET
   at exports._errnoException (util.js:746:11)
   at TCP.onread (net.js:559:26)

The Reason:

grunt-contrib-imagemin cannot download and test 3 dependencies

imagemin-gifsicle

imagemin-optipng

imagemin-jpegtran

Solution

  1. install grunt-contrib-imagemin 0.9.4 version

    npm cache clear
    
    npm uninstall grunt-contrib-imagemin
    
    npm install --save-dev grunt-contrib-imagemin@.0.9.4
    
  2. gifsicle

    Download the gifsicle.exe 32 bit from here

    unzip it
    make a folder called vendor on yourapp\node_modules\grunt-contrib- imagemin\node_modules\imagemin\node_modules\imagemin-gifsicle\node_modules\gifsicle\

    copy extracted gifsicle.exe to vendor folder

    Now you have fixed the gifsicle issue. do not get exited two more to go :)

  3. optipng

    Download optipng.exe from here make a folder called vendor on yourapp\node_modules\grunt-contrib- imagemin\node_modules\imagemin\node_modules\imagemin-optipng\node_module\optipng-bin\

    copy extracted optipng.exe here. Now you have fixed the optipng issue. do not get exited yet one more to go :)

  4. jpegtran

    Download jpegtran.exe and libjpeg-62.dll put them in vendor folder inside

    yourapp\node_modules\grunt-contrib- imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_module\jpegtran-bin\

Hooray, you are done. and your

 Grunt imagemin:dist

command will be done successfully

Remember

if you install grunt again which is consequently will install grunt-contrib-imagemin these folders will not be overwritten. However for the first and clean installation you need to go through these steps.

0

I have the same problem atm. I've tried an older version and it worked perfectly. There is a issue in thee git repository so you are not alone on this one ;)

https://github.com/gruntjs/grunt-contrib-imagemin/issues/273

0

According to the Github Ticket #273: (Fatal error: This socket is closed) it is caused by the jpegtran-bin Issue #54. Both issued are solved and closed now.

Installing grunt-contrib-imagemin 0.9.2 solved this for me by running

npm cache clean
npm install grunt-contrib-imagemin --save-dev
Max
  • 121
  • 6