致命错误:当我测试grunt-contrib-imagemin时,此套接字已关闭

时间:2014-10-27 09:53:49

标签: gruntjs imagemin

我正在测试jpg minify的插件grunt-contrib-imagemin。但它总是失败的 运行“imagemin:dynamic”(imagemin)任务 致命错误:此套接字已关闭。

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
      }]
    }
        }
    });

4 个答案:

答案 0 :(得分:1)

尝试重新安装grunt-contrib-imagemin:

npm cache clean
npm install grunt-contrib-imagemin --save-dev

答案 1 :(得分:1)

问题:

做的时候

npm install

您收到错误:

 ? 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)

原因:

grunt-contrib-imagemin无法下载和测试3个依赖项

imagemin-gifsicle

imagemin-使用OptiPNG

imagemin-jpegtran

<强>解决方案

  1. 安装grunt-contrib-imagemin 0.9.4版本

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

    here

    下载 gifsicle.exe 32位 解压缩它 在yourapp \ node_modules \ grunt-contrib-imagemin \ node_modules \ imagemin \ node_modules \ imagemin-gifsicle \ node_modules \ gifsicle \

    上创建一个名为vendor的文件夹

    将提取的 gifsicle.exe 复制到供应商文件夹

    现在你已经修复了gifsicle问题。不要再退出两次了:)

  3. <强>使用OptiPNG

    从此处下载 optipng.exe 在yourapp \ node_modules \ grunt-contrib-imagemin \ node_modules \ imagemin \ node_modules \ imagemin-optipng \ node_module \ optipng-bin \

    上创建一个名为vendor的文件夹

    在此处复制解压缩的 optipng.exe 。 现在你已经修复了optipng问题。不要再退出了一次:)

  4. <强> jpegtran

    下载 jpegtran.exe libjpeg-62.dll 将它们放在 vendor 文件夹里面

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

  5. 好吧,你做完了。和你的

     Grunt imagemin:dist
    

    命令将成功完成

    <强>记住

    如果你再次安装grunt,那么将安装grunt-contrib-imagemin这些文件夹不会被覆盖。但是,对于第一个和干净的安装,您需要完成这些步骤。

答案 2 :(得分:0)

我有同样的问题atm。 我尝试过旧版本,效果很好。 在git存储库中存在一个问题,因此您并不是唯一的问题;)

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

答案 3 :(得分:0)

根据Github Ticket #273: (Fatal error: This socket is closed) ,它是由jpegtran-bin Issue #54引起的。两个发布现在都已解决和关闭。

安装grunt-contrib-imagemin 0.9.2通过运行

为我解决了这个问题
npm cache clean
npm install grunt-contrib-imagemin --save-dev