imagemin / jpegoptim-bin

jpegoptim bin-wrapper that makes it seamlessly available as a local dependency
https://github.com/tjko/jpegoptim
MIT License
24 stars 8 forks source link

Doesn't work on new Apple M1 chip #21

Open cimmwolf opened 3 years ago

cimmwolf commented 3 years ago

Hello. I have an error when install package. How can I use it on Apple Silicone?

yarn add v1.22.10
info No lockfile found.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
error /Users/denis/Projects/Jpegoptim/node_modules/jpegoptim-bin: Command failed.
Exit code: 1
Command: node lib/install.js
Arguments: 
Directory: /Users/denis/Projects/Jpegoptim/node_modules/jpegoptim-bin
Output:
⚠ Command failed: /Users/denis/Projects/Jpegoptim/node_modules/jpegoptim-bin/vendor/jpegoptim --version
dyld: Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.9.dylib
  Referenced from: /Users/denis/Projects/Jpegoptim/node_modules/jpegoptim-bin/vendor/jpegoptim
  Reason: no suitable image found.  Did find:
    /usr/local/opt/jpeg/lib/libjpeg.9.dylib: mach-o, but wrong architecture
    /opt/homebrew/Cellar/jpeg/9d/lib/libjpeg.9.dylib: mach-o, but wrong architecture

  ⚠ jpegoptim pre-build test failed
  ℹ compiling from source
  ✖ Error: Command failed: /bin/sh -c ./configure --prefix="/Users/denis/Projects/Jpegoptim/node_modules/jpegoptim-bin/vendor" --bindir="/Users/denis/Projects/Jpegoptim/node_modules/jpegoptim-bin/vendor"

checking build system type... arm-apple-darwin20.3.0
checking host system type... arm-apple-darwin20.3.0
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for a BSD-compatible install... /usr/bin/install -c
checking whether make sets $(MAKE)... yes
checking for jpeg_read_header in -ljpeg... no
Cannot find libjpeg or you have too old version (v6 or later required).

    at /Users/denis/Projects/Jpegoptim/node_modules/execa/index.js:231:11
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Promise.all (index 0)
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
1000ch commented 3 years ago

@cimmwolf Would you try brew reinstall jpeg before installing jpegoptim-bin?

Golmote commented 3 years ago

Hello, I'm encountering the same issue. brew reinstall jpeg did not fix the issue for me.

Golmote commented 3 years ago

Hello again, thanks to help from the jpegoptim owner, I managed to install jpegoptim-bin but I had to set flags first:

CPPFLAGS="-I /opt/homebrew/Cellar/jpeg/9d/include" LDFLAGS="-L /opt/homebrew/Cellar/jpeg/9d/lib" npm install --save-dev jpegoptim-bin

This works, but any chance it could be detected and applied automatically?

ramonfritsch commented 2 years ago

Hello again, thanks to help from the jpegoptim owner, I managed to install jpegoptim-bin but I had to set flags first:

CPPFLAGS="-I /opt/homebrew/Cellar/jpeg/9d/include" LDFLAGS="-L /opt/homebrew/Cellar/jpeg/9d/lib" npm install --save-dev jpegoptim-bin

This works, but any chance it could be detected and applied automatically?

This helped me, changing 9d to 9e (probably a newer jpeg version) did the trick. Thanks!

rynop commented 2 years ago
 CPPFLAGS="-I /opt/homebrew/Cellar/jpeg/9e/include" LDFLAGS="-L /opt/homebrew/Cellar/jpeg/9e/lib/" yarn add -DT jpegoptim-bin

^ works to get the package installed on my arm64 M1 (and into package.json), however other developers that come do a yarn install it fails with the same error.

The work-around I came up with is to run the following in an .*rc/bootstrap:

    export LDFLAGS="-L $(brew --prefix jpeg)/lib/"
    export CPPFLAGS="-I $(brew --prefix jpeg)/include"

Note: this accounts for brew version upgrades (9 d/e discrepancy that @ramonfritsch mentions)

Not ideal obviously.

toFrankie commented 1 year ago

👀