mozjpeg-bin
mozjpeg-bin copied to clipboard
Apple Silicon M1 builds fail with incorrect path to libpng libraries
I'm reporting an issue on an M1 without Rosetta 2.
Environment:
- Node version: v16.4.0
- MacOS version: 11.4
- libpng version: 1.6.37
Reproduce issue:
First, without installing a number of pre-requisites I get the following after running yarn add imagemin-mozjpeg
in an empty project:
error /Users/rgillson/Desktop/Projects/Repos/Private/Web/test/node_modules/mozjpeg: Command failed.
Exit code: 1
Command: node lib/install.js
Arguments:
Directory: /Users/rgillson/Desktop/Projects/Repos/Private/Web/test/node_modules/mozjpeg
Output:
⚠ spawn Unknown system error -86
⚠ mozjpeg pre-build test failed
ℹ compiling from source
✖ Error: Command failed: /bin/sh -c autoreconf -fiv
/bin/sh: autoreconf: command not found
at /Users/rgillson/Desktop/Projects/Repos/Private/Web/test/node_modules/bin-build/node_modules/execa/index.js:231:11
After running brew install automake autoconf libtool m4 nasm libpng pkg-config
and attempting again, yarnpkg now exits with:
error /Users/rgillson/Desktop/Projects/Repos/Personal/Private/Web/test/node_modules/mozjpeg: Command failed.
Exit code: 1
Command: node lib/install.js
Arguments:
Directory: /Users/rgillson/Desktop/Projects/Repos/Personal/Private/Web/test/node_modules/mozjpeg
Output:
⚠ spawn Unknown system error -86
⚠ mozjpeg pre-build test failed
ℹ compiling from source
✖ Error: Command failed: /bin/sh -c make -j8
clang: error: no such file or directory: '/usr/local/lib/libpng16.a'
make[2]: *** [cjpeg] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
/Library/Developer/CommandLineTools/usr/bin/make all-recursive
Making all in java
echo timestamp > classnoinst.stamp
Making all in simd
GEN jsimdcfg.inc
/Library/Developer/CommandLineTools/usr/bin/make all-am
CC libsimd_la-jsimd_arm64.lo
CPPAS jsimd_arm64_neon.lo
CCLD libsimd.la
Making all in md5
CC md5cmp-md5cmp.o
CC md5cmp-md5.o
CC md5cmp-md5hl.o
CCLD md5cmp
CC cjpeg-cdjpeg.o
CC cjpeg-cjpeg.o
CC cjpeg-rdgif.o
CC cjpeg-rdtarga.o
CC cjpeg-rdbmp.o
CC cjpeg-rdjpeg.o
CC cjpeg-rdppm.o
CC cjpeg-rdswitch.o
CC cjpeg-rdpng.o
CC jcapimin.lo
CC jcapistd.lo
CC jccoefct.lo
CC jccolor.lo
CC jcdctmgr.lo
CC jcext.lo
CC jchuff.lo
CC jcinit.lo
CC jcmainct.lo
CC jcmarker.lo
CC jcmaster.lo
CC jcomapi.lo
CC jcparam.lo
CC jcphuff.lo
CC jcprepct.lo
CC jcsample.lo
CC jctrans.lo
CC jdapimin.lo
CC jdapistd.lo
CC jdatadst.lo
CC jdatasrc.lo
CC jdcoefct.lo
CC jdcolor.lo
CC jddctmgr.lo
CC jdhuff.lo
CC jdinput.lo
CC jdmainct.lo
CC jdmarker.lo
CC jdmaster.lo
CC jdmerge.lo
CC jdphuff.lo
CC jdpostct.lo
CC jdsample.lo
CC jdtrans.lo
CC jerror.lo
CC jfdctflt.lo
CC jfdctfst.lo
CC jfdctint.lo
CC jidctflt.lo
CC jidctfst.lo
CC jidctint.lo
CC jidctred.lo
CC jquant1.lo
CC jquant2.lo
CC jutils.lo
CC jmemmgr.lo
CC jmemnobs.lo
CC jaricom.lo
CC jcarith.lo
CC jdarith.lo
CC djpeg-cdjpeg.o
CC djpeg-djpeg.o
CC djpeg-rdcolmap.o
CC djpeg-rdswitch.o
CC djpeg-wrgif.o
CC djpeg-wrppm.o
CC djpeg-wrbmp.o
CC djpeg-wrtarga.o
CC jpegtran.o
CC rdswitch.o
CC cdjpeg.o
CC transupp.o
CC rdjpgcom.o
CC wrjpgcom.o
CC tjbench-tjbench.o
CC tjbench-bmp.o
CC tjbench-tjutil.o
CC tjbench-rdbmp.o
CC tjbench-rdppm.o
CC tjbench-wrbmp.o
CC tjbench-wrppm.o
CC libturbojpeg_la-jcapimin.lo
CC libturbojpeg_la-jcapistd.lo
CC libturbojpeg_la-jccoefct.lo
CC libturbojpeg_la-jccolor.lo
CC libturbojpeg_la-jcdctmgr.lo
CC libturbojpeg_la-jcext.lo
CC libturbojpeg_la-jchuff.lo
CC libturbojpeg_la-jcinit.lo
CC libturbojpeg_la-jcmainct.lo
CC libturbojpeg_la-jcmarker.lo
CC libturbojpeg_la-jcmaster.lo
CC libturbojpeg_la-jcomapi.lo
CC libturbojpeg_la-jcparam.lo
CC libturbojpeg_la-jcphuff.lo
CC libturbojpeg_la-jcprepct.lo
CC libturbojpeg_la-jcsample.lo
CC libturbojpeg_la-jctrans.lo
CC libturbojpeg_la-jdapimin.lo
CC libturbojpeg_la-jdapistd.lo
CC libturbojpeg_la-jdatadst.lo
CC libturbojpeg_la-jdatasrc.lo
CC libturbojpeg_la-jdcoefct.lo
CC libturbojpeg_la-jdcolor.lo
CC libturbojpeg_la-jddctmgr.lo
CC libturbojpeg_la-jdhuff.lo
CC libturbojpeg_la-jdinput.lo
CC libturbojpeg_la-jdmainct.lo
CC libturbojpeg_la-jdmarker.lo
CC libturbojpeg_la-jdmaster.lo
CC libturbojpeg_la-jdmerge.lo
CC libturbojpeg_la-jdphuff.lo
CC libturbojpeg_la-jdpostct.lo
CC libturbojpeg_la-jdsample.lo
CC libturbojpeg_la-jdtrans.lo
CC libturbojpeg_la-jerror.lo
CC libturbojpeg_la-jfdctflt.lo
CC libturbojpeg_la-jfdctfst.lo
CC libturbojpeg_la-jfdctint.lo
CC libturbojpeg_la-jidctflt.lo
CC libturbojpeg_la-jidctfst.lo
CC libturbojpeg_la-jidctint.lo
CC libturbojpeg_la-jidctred.lo
CC libturbojpeg_la-jquant1.lo
CC libturbojpeg_la-jquant2.lo
CC libturbojpeg_la-jutils.lo
CC libturbojpeg_la-jmemmgr.lo
CC libturbojpeg_la-jmemnobs.lo
CC libturbojpeg_la-jaricom.lo
CC libturbojpeg_la-jcarith.lo
CC libturbojpeg_la-jdarith.lo
CC libturbojpeg_la-turbojpeg.lo
CC libturbojpeg_la-transupp.lo
CC libturbojpeg_la-jdatadst-tj.lo
CC libturbojpeg_la-jdatasrc-tj.lo
CC jcstest.o
CC jpegyuv.o
CC yuvjpeg.o
CC tjunittest.o
CC tjutil.o
CCLD libjpeg.la
CCLD libturbojpeg.la
CCLD cjpeg
CCLD djpeg
CCLD jpegtran
CCLD rdjpgcom
CCLD wrjpgcom
CCLD jpegyuv
CCLD jcstest
CCLD yuvjpeg
at /Users/rgillson/Desktop/Projects/Repos/Personal/Private/Web/test/node_modules/execa/index.js:231:11
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Promise.all (index 0)
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Finally, I have confirmed the library is symlinked at /opt/homebrew/lib/libpng16.a
to /opt/homebrew/Cellar/libpng/1.6.37/lib/libpng16.a
.
https://github.com/imagemin/mozjpeg-bin/blob/726d6848453a1c77595d29257903bc1fe2995ae5/lib/install.js#L19
It seems the location is hardcoded based on previous install location of libpng before Homebrew moved everything under /opt/homebrew
. I think a more futureproof implementation of the build would be to find where the relevant libraries are installed rather than depending on them being in a specific location.
Workaround
For now, it was enough to: sudo ln -s /opt/homebrew/Cellar/libpng/1.6.37/lib/libpng16.a libpng16.a
which resulted in a successful package install