5

我正在测试用于 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

4 回答 4

1

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

npm cache clean
npm install grunt-contrib-imagemin --save-dev
于 2014-12-11T18:02:14.107 回答
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

    从这里下载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.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.exelibjpeg-62.dll 放到vendor文件夹里面

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

万岁,你完成了。和你的

 Grunt imagemin:dist

命令将成功完成

记住

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

于 2015-07-03T04:24:00.540 回答
0

根据 Github Ticket #273 :(致命错误:此套接字已关闭)它是由 jpegtran-bin问题 #54引起的。两者都已解决并已关闭。

安装 grunt-contrib-imagemin 0.9.2 通过运行为我解决了这个问题

npm cache clean
npm install grunt-contrib-imagemin --save-dev
于 2015-01-26T16:26:03.630 回答
0

我有同样的问题atm。我试过一个旧版本,它工作得很好。你的 git 存储库中有一个问题,所以你并不孤单;)

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

于 2014-12-12T08:31:47.503 回答