twolfson / gulp.spritesmith

Convert a set of images into a spritesheet and CSS variables via gulp
The Unlicense
1.07k stars 81 forks source link

imagemin error in stream #109

Closed linqianwarm closed 7 years ago

linqianwarm commented 7 years ago

as long as I add the imagemin() task in the pipeline as the introduction said, there is a error thrown. what's wrong?

twolfson commented 7 years ago

What's the error you are receiving and can you paste your gulpfile?

linqianwarm commented 7 years ago

`var gulp = require('gulp'); var buffer = require('vinyl-buffer'); var csso = require('gulp-csso'); var imagemin = require('gulp-imagemin'); var merge = require('merge-stream');

var spritesmith = require('gulp.spritesmith');

gulp.task('sprite', function(){ var spriteData = gulp.src('src/www/material/images/*.png').pipe(spritesmith({ imgName:'sprite.png', cssName: 'sprite.css', padding: 5 }));

var imgStream = spriteData.img
.pipe(buffer())
.pipe(imagemin())
.pipe(gulp.dest('src/www/material/imgsprite/'));

var cssStream = spriteData.css
.pipe(csso())
.pipe(gulp.dest('src/www/material/csssprite/'));

return merge(imgStream, cssStream);

})`

twolfson commented 7 years ago

That looks fine to me, what's the error you are receiving?

linqianwarm commented 7 years ago

image

appreicate ur reply~

twolfson commented 7 years ago

ENOENT means the file cannot be found (i.e. error no entity). This means something is going wrong when your system is looking for optipng. Here's a comparable error demonstration:

require('child_process').spawn('not-a-program')
// Results in:
Error: spawn not-a-program ENOENT
    at exports._errnoException (util.js:911:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:189:32)
    at onErrorNT (internal/child_process.js:355:16)
    at nextTickCallbackWith2Args (node.js:458:9)
    at process._tickDomainCallback (node.js:413:17)

The strange thing is optipng is automatically installed via imagemin:

https://github.com/sindresorhus/gulp-imagemin/blob/v3.1.1/index.js#L115

https://github.com/sindresorhus/gulp-imagemin/blob/v3.1.1/package.json#L55

https://github.com/imagemin/imagemin-optipng/blob/v5.2.1/index.js#L4

https://github.com/imagemin/optipng-bin/blob/v3.1.2/package.json#L30

https://github.com/imagemin/optipng-bin/blob/v3.1.2/lib/install.js

https://github.com/imagemin/optipng-bin/blob/v3.1.2/lib/index.js

My shot in the dark would be that somehow this download action never ran (e.g. you are using an --ignore-scripts during npm install). My suggestion would be to remove your node modules and reinstall them:

rm -r node_modules
npm install

If the problem persists, look at your npm configuration and see if there is anything odd:

npm config list

Did you find this help useful? Consider supporting @twolfson via a donation: http://twolfson.com/support-me