imagemin: mozjpeg pre-build test failed

not sure if I should be posting this here or in mozjpeg but mozjpeg is failing for me on OS X 10.11:

optipng-bin@3.1.1 postinstall /Users/xxx/Sites/white-label/node_modules/gulp-imagemin/node_modules/imagemin-optipng/node_modules/optipng-bin
> node lib/install.js

  ✔ optipng pre-build test passed successfully

> mozjpeg@4.1.1 postinstall /Users/xxx/Sites/white-label/node_modules/gulp-imagemin/node_modules/imagemin-mozjpeg/node_modules/mozjpeg
> node lib/install.js

  ⚠ The `/Users/xxx/Sites/white-label/node_modules/gulp-imagemin/node_modules/imagemin-mozjpeg/node_modules/mozjpeg/vendor/cjpeg` binary doesn't seem to work correctly
  ⚠ mozjpeg pre-build test failed
  ℹ compiling from source
  ✖ Error: autoreconf -fiv && ./configure --disable-shared --prefix="/Users/xxx/Sites/white-label/node_modules/gulp-imagemin/node_modules/imagemin-mozjpeg/node_modules/mozjpeg/vendor" --bindir="/Users/xxx/Sites/white-label/node_modules/gulp-imagemin/node_modules/imagemin-mozjpeg/node_modules/mozjpeg/vendor" --libdir="/Users/xxx/Sites/white-label/node_modules/gulp-imagemin/node_modules/imagemin-mozjpeg/node_modules/mozjpeg/vendor" && make --jobs=8 && make install --jobs=8
Command failed: /bin/sh -c autoreconf -fiv
/bin/sh: autoreconf: command not found

    at ChildProcess.exithandler (child_process.js:213:12)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:827:16)
    at Socket.<anonymous> (internal/child_process.js:319:11)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at Pipe._onclose (net.js:477:12)

> gifsicle@3.0.3 postinstall /Users/xxx/Sites/white-label/node_modules/gulp-imagemin/node_modules/imagemin-gifsicle/node_modules/gifsicle
> node lib/install.js

  ✔ gifsicle pre-build test passed successfully

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 6
  • Comments: 53 (6 by maintainers)

Most upvoted comments

On MacOS 10.11.6, I did this

brew install automake autoconf libtool dpkg pkgconfig nasm libpng

I don’t know if @bshack is still having problems with that, but I was struggling with the same problem yesterday and I think that I’ve found a solution.

My Scenario: building a project that uses imagemin inside a docker container using alpine linux.

Solution: install the following alpine packages:

  • libpng-dev
  • autoconf
  • automake
  • make
  • g++
  • libtool
  • nasm

After installing that, I was able to compile the binaries.

I don’t know if it helps, but I’m adding it here, so anyone can try this when having same problems.

I got a similar error. Here’s what I did to fix it; hopefully this helps someone else!

  1. Update Xcode command line tools to latest release
  2. brew install nasm (I was using the bundled OS X version 0.98.40, now using 2.11.08)
  3. npm cache clean
  4. npm install

Still getting an error with the cjpeg binary, but the build from source works now.

This bug reproduced on CentOS 6.8 witn node.js v6.9.4. But when I install yum install wget autoconf automake gcc nasm libtool, I successfully compiled mozjpeg

mozjpeg@4.1.1 postinstall /home/bitrix/serv_opti/node_modules/mozjpeg node lib/install.js

⚠ The /home/bitrix/serv_opti/node_modules/mozjpeg/vendor/cjpeg binary doesn’t seem to work correctly ⚠ mozjpeg pre-build test failed ℹ compiling from source ✔ mozjpeg built successfully

It is not Alpine Linux, but may be it will help you to find a right solution .

FROM node:latest

RUN set -ex \
    && apt-get update \
    && apt-get install -y --no-install-recommends \
        autoconf \
        libtool \
        libpng-dev \
        pkg-config \
        nasm \
    && wget -q -O /tmp/libpng12.deb http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb \
         && dpkg -i /tmp/libpng12.deb \
         && rm /tmp/libpng12.deb \
    && rm -rf /var/lib/apt/lists/* \
    && rm -rf /tmp/*

RUN mkdir /var/www && chown -R node:node /var/www
WORKDIR /var/www

On Ubuntu 16.04, sudo apt install nasm worked for me!

if you are using macOS with M1 chip and, getting pre-build failed, you could try following steps and run your installation again. It works for me.

  1. Goto the applications, find iTerm ,
  2. Right click on it and click Get Info​​​​​​​
  3. Check the Open with Rosseta, Click close the dialog
  4. Open iTerm now and, it will ask you to download some updates. Complete the updates.
  5. Quit iTerm now
  6. Right click on the iTerm again and uncheck the Open with Rosseta again
  7. Try your yarn or test it using npm i mozjpeg; It should work

anyone ever figured how to natively install this in alpine without requiring to build from source?

Still no dice here on CentOS 7.

# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core)
# yum install nasm gcc make autoconf automake m4 libtool wget curl libjpeg-turbo-utils libjpeg-turbo-devel libpng libpng-devel
Loaded plugins: fastestmirror, priorities, replace, versionlock
Loading mirror speeds from cached hostfile
 * base: mirror.pac-12.org
 * epel: mirrors.cat.pdx.edu
 * extras: mirrors.cat.pdx.edu
 * updates: mirrors.kernel.org
 * webtatic: uk.repo.webtatic.com
Package nasm-2.10.07-7.el7.x86_64 already installed and latest version
Package gcc-4.8.5-16.el7_4.1.x86_64 already installed and latest version
Package 1:make-3.82-23.el7.x86_64 already installed and latest version
Package autoconf-2.69-11.el7.noarch already installed and latest version
Package automake-1.13.4-3.el7.noarch already installed and latest version
Package m4-1.4.16-10.el7.x86_64 already installed and latest version
Package libtool-2.4.2-22.el7_3.x86_64 already installed and latest version
Package wget-1.14-15.el7_4.1.x86_64 already installed and latest version
Package curl-7.29.0-42.el7_4.1.x86_64 already installed and latest version
Package libjpeg-turbo-utils-1.2.90-5.el7.x86_64 already installed and latest version
Package libjpeg-turbo-devel-1.2.90-5.el7.x86_64 already installed and latest version
Package 2:libpng-1.5.13-7.el7_2.x86_64 already installed and latest version
Package 2:libpng-devel-1.5.13-7.el7_2.x86_64 already installed and latest version
Nothing to do

and then:

# npm install -g mozjpeg
npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
/usr/bin/mozjpeg -> /usr/lib/node_modules/mozjpeg/cli.js

> mozjpeg@5.0.0 postinstall /usr/lib/node_modules/mozjpeg
> node lib/install.js

  ⚠ EACCES: permission denied, mkdir '/usr/lib/node_modules/mozjpeg/vendor'
  ⚠ mozjpeg pre-build test failed
  ℹ compiling from source
/usr/lib/node_modules/mozjpeg/node_modules/onetime/index.js:15
				throw new Error(fnName + ' can only be called once.');
				^

Error: callback() can only be called once.
    at onetime (/usr/lib/node_modules/mozjpeg/node_modules/onetime/index.js:15:11)
    at /usr/lib/node_modules/mozjpeg/node_modules/download/index.js:156:5
    at ConcatStream.<anonymous> (/usr/lib/node_modules/mozjpeg/node_modules/concat-stream/index.js:36:43)
    at ConcatStream.emit (events.js:165:20)
    at finishMaybe (/usr/lib/node_modules/mozjpeg/node_modules/readable-stream/lib/_stream_writable.js:620:14)
    at endWritable (/usr/lib/node_modules/mozjpeg/node_modules/readable-stream/lib/_stream_writable.js:628:3)
    at ConcatStream.Writable.end (/usr/lib/node_modules/mozjpeg/node_modules/readable-stream/lib/_stream_writable.js:584:41)
    at DuplexWrapper.onend (/usr/lib/node_modules/mozjpeg/node_modules/readable-stream/lib/_stream_readable.js:577:10)
    at Object.onceWrapper (events.js:255:19)
    at DuplexWrapper.emit (events.js:165:20)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mozjpeg@5.0.0 postinstall: `node lib/install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the mozjpeg@5.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-02-13T03_25_29_915Z-debug.log

@bshack Do you have a Package lock file that was generated from another OS? I faced this issue when a package-lock.json file was created in Windows system and then we tried to deploy the code in Jenkins(Linux) environment. Deleting the package-lock.json file solved the issue for me. Hope this helps

Okay so just try to npm install imagemin again 😃

That worked for me but you could also cd into node_modules > mozjpeg > test and run node test

That should try to build it but you need to have done what @chrisvanpatten said

Try running also node node_modules/mozjpeg/lib/install.js to try the build manually

This fixed the source build for me on Mac Sierra:

sudo port install automake autoconf libtool dpkg pkgconfig nasm