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

events.js:72 // unhandled 'error' event; Error: This socket is closed #85

Closed
kyleva opened this issue Dec 17, 2014 · 5 comments
Closed

Comments

@kyleva
Copy link

kyleva commented Dec 17, 2014

I'm using the gulp-imagemin plugin to minify image files. Unfortunately, every time I save into the image directory specified in my watch task (gulp.watch('src/assets/images/**/*', ['images']);), there is the following error:

Starting 'images'...

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: This socket is closed.
    at Socket._write (net.js:637:19)
    at doWrite (_stream_writable.js:225:10)
    at writeOrBuffer (_stream_writable.js:215:5)
    at Socket.Writable.write (_stream_writable.js:182:11)
    at Socket.write (net.js:615:40)
    at Socket.Writable.end (_stream_writable.js:340:10)
    at Socket.end (net.js:396:31)
    at Through2._transform (C:\Storage\Web\uva\node_modules\gulp-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\index.js:68:12)
    at Through2.Transform._read (C:\Storage\Web\uva\node_modules\gulp-imagemin\node_modules\imagemin\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:184:10)
    at Through2.Transform._write (C:\Storage\Web\uva\node_modules\gulp-imagemin\node_modules\imagemin\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:172:12)

Here's my images task:

gulp.task('images', function(){
    gulp.src('src/assets/images/**/*')
        .pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true}))
        .pipe(gulp.dest('dist/assets/images'))
        .pipe(livereload())
        .pipe(notify({message: "Image task complete"}));
});

What I've tried so far

  • npm cache clean followed by deleting all everything in node_modules folder and running npm install
  • Running my images task and targeting only one image (e.g. gulp.src('src/assets/images/background-image.png'). This was mentioned in Error That Fixes by Restarting #45.
  • Specifying separate image formats as an argument for gulp.src. (e.g. gulp.src(['images/**/*.png', 'images/**/*.jpg', 'images/**/*.svg']). This was mentioned in Error That Fixes by Restarting #45.
  • Uninstall gulp-imagemin and reinstall gulp-imagemin
  • npm install jpegtran-bin (there appeared to be an error when installing this, more on this in a sec). This was mentioned in grunt-contrib-imagemin #272.
  • Uninstall/reinstall node.js

Now, one thing I noticed a problem with .. was when installing gulp-imagemin there was an error with one of it's dependencies. When installing there were some errors with jpegtran so I manually attempted to install jpegtran-bin. When running this command I received the following result:

>npm install jpegtran-bin
npm WARN package.json uva@0.1.0 No repository field.
\
> jpegtran-bin@2.0.2 postinstall C:\Storage\Web\uva\node_modules\jpegtran-bin
> node lib/install.js

  ‼ ENOENT, stat 'C:\Storage\Web\uva\node_modules\jpegtran-bin\vendor\jpegtran.exe'
  ‼ jpegtran pre-build test failed
  i compiling from source
  x Error: Command failed: '.' is not recognized as an internal or external command,
operable program or batch file.

    at ChildProcess.exithandler (child_process.js:648:15)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:756:16)
    at Process.ChildProcess._handle.onexit (child_process.js:823:5)
jpegtran-bin@2.0.2 node_modules\jpegtran-bin
├── logalot@2.1.0 (figures@1.3.5, squeak@1.2.0)
├── bin-build@2.1.0 (rimraf@2.2.8, exec-series@1.0.1, tempfile@1.1.0, download@3.2.0)
└── bin-wrapper@2.1.1 (os-filter-obj@1.0.0, is-path-global@1.0.1, download-status@2.1.0, lnfs@1.0.0, bin-version-check@1.0.0, npm-installed@1.0.0, bin-check@1.0.0, globby@0.1.1, download@3.2.0)

My gulpfile.js:

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    autoprefixer = require('gulp-autoprefixer'),
    cache = require('gulp-cache'),
    concat = require('gulp-concat'),
    imagemin = require('gulp-imagemin'),
    jshint = require('gulp-jshint'),
    livereload = require('gulp-livereload'),
    minifycss = require('gulp-minify-css'),
    notify = require('gulp-notify'),
    rename = require('gulp-rename'),
    uglify = require('gulp-uglify'),
    htmlmin = require('gulp-htmlmin'),
    webserver = require('gulp-webserver'),
    del = require('del');

gulp.task('webserver', function(){
    gulp.src('src')
        .pipe(webserver({
            livereload: true,
            open: true
        })
    );
});

gulp.task('styles', function(){
    gulp.src('src/assets/styles/main.scss')
        .pipe(sass())
        .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
        .pipe(gulp.dest('src/assets/styles'))
        .pipe(rename({ suffix: '.min' }))
        .pipe(minifycss())
        .pipe(gulp.dest('dist/assets/styles'))
        .pipe(livereload())
        .pipe(notify({ message: 'Styles task complete' }));

});

gulp.task('scripts', function(){
    gulp.src('src/assets/scripts/**/*.js')
        .pipe(jshint('.jshintrc'))
        .pipe(jshint.reporter('default'))
        .pipe(concat('main.js'))
        .pipe(gulp.dest('dist/assets/scripts'))
        .pipe(rename({suffix: '.min'}))
        .pipe(uglify())
        .pipe(gulp.dest('dist/assets/scripts'))
        .pipe(livereload())
        .pipe(notify({ message: 'Scripts task complete'}));
});

gulp.task('html', function(){
    gulp.src('src/*.html')
        .pipe(htmlmin({ collapseWhitespace: true, removeComments: true, removeAttributeQuotes: true, removeRedundantAttributes: true, minifyJS: true }))
        .pipe(gulp.dest('dist'))
        .pipe(livereload())
        .pipe(notify({ message: 'Html task complete' }));
});

gulp.task('images', function(){
    gulp.src('src/assets/images/**/*')
        .pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true}))
        .pipe(gulp.dest('dist/assets/images'))
        .pipe(livereload())
        .pipe(notify({message: "Image task complete"}));
});

gulp.task('clean', function(cb){
    del([
        'dist/assets/styles',
        'dist/assets/scripts',
        'dist/assets/images'
    ], cb);
});

gulp.task('default', ['clean'], function(){
    gulp.start('styles', 'scripts', 'images', 'html');
});

gulp.task('serve', function(){
    gulp.start('webserver', 'watch');
});

gulp.task('watch', function(){
    livereload.listen();

    gulp.watch('src/assets/styles/**/*.scss', ['styles']);

    gulp.watch('src/assets/scripts/**/*.js', ['scripts']);

    gulp.watch('src/assets/images/**/*', ['images']);

    gulp.watch('src/*.html', ['html']);
});

Any idea on if there's a bug here or if I'm doing something incorrectly?

@kyleva
Copy link
Author

kyleva commented Dec 17, 2014

Changing the versions of the jpegtran-bin dependencies in node_modules/jpegtran-bin/package.json did the trick.

"dependencies": {
    //"bin-build": "^2.0.0",
    //"bin-wrapper": "^2.0.1",
    "bin-build": "^0.2.0",
    "bin-wrapper": "^0.4.0",
    "logalot": "^2.0.0"
  }

@kyleva kyleva closed this as completed Dec 17, 2014
@kyleva kyleva reopened this Dec 17, 2014
@kyleva
Copy link
Author

kyleva commented Dec 17, 2014

See: jpegtran-bin #54.

@kyleva kyleva closed this as completed Dec 17, 2014
@elartix
Copy link

elartix commented Dec 25, 2014

workaround imagemin/jpegtran-bin#54 (comment)

@IOZ
Copy link

IOZ commented Dec 25, 2014

Please, reopen this issue and make plugin updates according comments above.

@sindresorhus
Copy link
Owner

Please, realize this issue has nothing to do with this plugin directly.

Repository owner locked and limited conversation to collaborators Dec 25, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants