question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using mozjpeg to compress pictures will result in errors!

See original GitHub issue
  • Node Version: 11.15.0
  • Imagemin Version: 7.0.1
  • Gulp-Imagemin Version: 7.0.0 Imagemin 7.0.0 ^ compress JPEG pictures with mozjpeg。 When I use mozjpeg to compress JPEG images, the tool throws an exception. But pictures in other formats are normally compressed.
import imagemin from 'gulp-imagemin';
const ImageTask = () => {
    return src(['src/images/*.{png,jpg,jpeg,svg,gif}'])
            .pipe(imagemin(
                [
                    imagemin.gifsicle({
                        interlaced: true,
                        optimizationLevel: 3,
                    }),
                    imagemin.mozjpeg({
                        quality: 75,
                        progressive: true
                    }),
                    imagemin.optipng({ optimizationLevel: 5}),
                    imagemin.svgo(),
                ], {
                    silent: false
                }
            ))
            .pipe(dest('dist/images'))
}

The details of the error are as follows

Message:
    spawn /Users/cuijianwei/WebstormProjects/testproject/gulp-demo/node_modules/mozjpeg/vendor/cjpeg ENOENT
Details:
    errno: ENOENT
    code: ENOENT
    syscall: spawn /Users/cuijianwei/WebstormProjects/testproject/gulp-demo/node_modules/mozjpeg/vendor/cjpeg
    path: /Users/cuijianwei/WebstormProjects/testproject/gulp-demo/node_modules/mozjpeg/vendor/cjpeg
    spawnargs: 
    stdout: 
    stderr: 
    failed: true
    signal: null
    cmd: /Users/cuijianwei/WebstormProjects/testproject/gulp-demo/node_modules/mozjpeg/vendor/cjpeg
    timedOut: false
    killed: false
    fileName: /Users/cuijianwei/WebstormProjects/testproject/gulp-demo/src/images/20171219195409_ez4Vu.jpeg
    domainEmitter: [object Object]
    domainThrown: false

I try to use mozjpeg command directly,like this

npx mozjpeg --help

Exception will still be thrown.

spawn /Users/cuijianwei/WebstormProjects/testproject/gulp-demo/node_modules/mozjpeg/vendor/cjpeg ENOENT

When I reduce imagemin to 6.2.0,Imagemin 6.2.0 compress JPEG pictures with jpegtran, and there’s no problem with jpegtran.

I hope this problem can be solved.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

2reactions
tangkunyincommented, Apr 19, 2021

In my case, the problem occurred after I upgrade npm to latest version(7.10.0). At first, I run rm -rf node_modules && npm install but it does’t work at all…

Then I try to check the mozjpeg folder and I found there was no vender/cjpeg. So I try to install packages whith yarn install and at last it works

For more details: https://github.com/npm/cli/issues/1905 https://github.com/npm/cli/issues/3100

image

0reactions
pm0ucommented, Nov 9, 2022

This seems to be an error with npm >= 7, we were able to get past this with npm install -g npm@6 although really not sure why

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compress in mozjpeg - Rust
Struct mozjpeg::Compress ... Compress image using input in this colorspace. ... By default errors cause unwind (panic) and unwind through the C code, ......
Read more >
Using mozjpeg to Create Efficient JPEGs
I'm excited to start using mozjpeg. This article is really helpful to get me going. You suggest doing some experimenting with the quality...
Read more >
Unable to compress large file with imageminMozjpeg?
I have been making a server on node which can take image files and upload on disk after compressing it. However, image with...
Read more >
How Image Optimization Decreased my Website's Page ...
Compress JPEGs with MozJPEG. To compress JPEG images, I used the MozJPEG tool from Mozilla which is available as an Imagemin plugin via...
Read more >
How to Resize an Image without Losing Quality
High-quality images are larger in file size, which can result in slow ... chosen your compression method (we're going to stick with MozJPEG...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found