sharp: Can't compile under Apple Silicon M1 arm64
Did you see the documentation relating to installation?
- yes
Have you ensured the architecture and platform of Node.js used for npm install is the same as the architecture and platform of Node.js used at runtime?
- yes
Are you using the latest version? Is the version currently in use as reported by npm ls sharp the same as the latest version as reported by npm view sharp dist-tags.latest?
- yes
What is the complete output of running npm install --verbose sharp? Have you checked this output for useful error messages?
> sharp@0.26.3 install /..../node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.0/libvips-8.10.0-darwin-arm64v8.tar.br
ERR! sharp Prebuilt libvips 8.10.0 binaries are not yet available for darwin-arm64v8
info sharp Attempting to build from source via node-gyp but this may fail due to the above error
info sharp Please see https://sharp.pixelplumbing.com/install for required dependencies
gyp info it worked if it ends with ok
....
-gdwarf-2 -mmacosx-version-min=11 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=c++14 -stdlib=libc++ -fexceptions -Wall -O3 -std=c++14 -stdlib=libc++ -MMD -MF ./Release/.deps/Release/obj.target/sharp/src/common.o.d.raw -c -o Release/obj.target/sharp/src/common.o ../src/common.cc
../src/common.cc:24:10: fatal error: 'vips/vips8' file not found
#include <vips/vips8>
^~~~~~~~~~~~
1 error generated.
make: *** [Release/obj.target/sharp/src/common.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/nw-gyp/lib/build.js:261:23)
gyp ERR! stack at ChildProcess.emit (events.js:315:20)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
gyp ERR! System Darwin 20.1.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/bin/nw-gyp" "rebuild"
gyp ERR! node -v v14.15.1
gyp ERR! nw-gyp -v v3.6.2
gyp ERR! not ok
Seems somehow libvips can’t be compiled from source
Any ideas?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 57
- Comments: 82 (10 by maintainers)
Commits related to this issue
- Docs: add section for Apple M1 users #2460 — committed to lovell/sharp by lovell 3 years ago
- Improve experience for those using Apple M1 devices #2460 - For Rosetta x64, prevent use of global ARM64 libvips - For ARM64, improve error message when global libvips not found — committed to lovell/sharp by lovell 3 years ago
🎉 I’m happy to report that thanks to the huge effort of the homebrew team and specially @fxcoudert, libvips can be fully installed on Apple Silicon M1 natively with all its dependencies!
Also for the most of the dependencies prebuild binaries “bottles” are available so installation goes really fast
brew info vipsbrew reinstall vipsbrew configthe same is valid for node and the sharp library now - they can run nicely native on M1 now!
I managed to run sharp thanks to @kenips comment Here’s what I have done:
Start with installing Mac ports. You will use ports to install libvips dependencies (follow next step)
Install these ports:
pkgconfigandglib2. Use this command to install ports:$ sudo port install [port-name]Now depending on the formats you’ll be handling, you’ll have to install the library for each format. Have look at the libvips dependency list and find them on Mac ports. In my case, jpg and png formats are enough, so I installed
libjpeg-turboandlibpngOnce you’ve installed the libraries, you’re ready to install libvips.
$ ./configure.$ makefollowed by$ sudo make installThis should install vips globally. Verify by running:
$ which vipsWhen libvips is globally installed, sharp will use the global version. So clean up your
node_modulesfolder and do a fresh install and you’re ready to go 👍Confirmed from #2467 that this is a non-issue once you have
libvipsinstall globally. I wasn’t able to install it viabrew, but downloaded the tarball and manually compiled fine, with the caveat that I had to manually specifyzlib’s location:PKG_CONFIG_PATH=/opt/homebrew/Cellar/zlib/1.2.11/lib/pkgconfig ./configure. Once installed globallysharpworks fine.I’m interested in this topic as well, did anyone figure a way to get sharp running under Apple silicon m1?
@gpetrov yes my procedure is very similar to @medhoover, however using homebrew:
pkg-config,zlibnormally withbrew installjpeg,libpng,libtiff,webpinstalled.PKG_CONFIG_PATH=/opt/homebrew/Cellar/zlib/1.2.11/lib/pkgconfig ./configure.I have installed a few packages prior to installing libvips, so there might be additional packages that I’ve missed for a mint install, so YMMV 😃.
Commit https://github.com/lovell/sharp/commit/4264c0577e8a0e74164a768bcd17e26d9593cd59, part of the forthcoming sharp v0.27.2, should improve the experience for those using Apple M1 devices.
From sharp v0.28.0 onwards, cross-compiled libvips binaries will be provided for
darwin-arm64- thank you @abarisain for helping with this.As soon as GitHub Actions or a similar CI service makes the M1 freely available to open source projects then natively compiled and tested prebuilt
darwin-arm64binaries will also be provided for sharp.Latest lts node isn’t arm64: building libvips with arm homebrew will produce a library that rosetta’d node can’t use. That’s what the linker is telling you: you’re trying to link an arm64 libvips within a x86_64 library.
I guess that sharp could implement an architecture check before trying to use a system libvips to help reduce how often this issue gets reported from people not familiar with multiple architectures and the resulting errors.
Lets summarize:
if you’re running a native arm64 node (15 and higher), you need to install libvips using arm homebrew. Note that macOS 11.2 currently breaks wasm in node 15: no fixed stable version has been tagged yet.
if you’re running an x64 node (14 and lower), do not install libvips using homebrew. If you already did it, remove it. Note that I experienced rosetta bugs when using libvips, ending up in segfaults.
if you need to have two node installs (one x64 and one arm64), you’re out of luck as brew will NOT build a “fat” libvips, and sharp will try to link with the system library and fail. You could manually make a fat libvips by using brew to compile both architectures and use “lipo” to make a fat libvips with both architectures, but this requires a little bit of knowledge of macOS’ way of making hybrid binaries.
To know what architecture your node uses, open up a terminal, fire up node and input
process.archI have very similar problem. npm I / yarn goes successfully(I got node 15 (arm64) and native libvips installed with brew ) but when launching Gatsby. I get
Error: Something went wrong installing the "sharp" module dlopen(/Users/.../node_modules/sharp/build/Release/sharp.node, 1): Symbol not found: __ZTVN 4vips7VOptionEThere’s a new (hopefully temporary) section in the sharp documentation directing Apple M1 users to install libvips via homebrew - please see https://sharp.pixelplumbing.com/install#apple-m1
Work is in progress to provide prebuilt, cross-compiled (and therefore possibly untested) libvips binaries for the “darwin-arm64v8” platform - please see https://github.com/lovell/sharp-libvips/pull/74
sharp v0.28.0 is now available and provides prebuilt (cross-compiled) libvips binaries for Apple M1 (darwin-arm64v8) so you no longer need to install vips via Homebrew.
https://sharp.pixelplumbing.com/install#apple-m1
Xcode and Python are still required as sharp must be built from source. As soon as GitHub Actions or a similar CI service makes M1-based machines freely available to open source projects then natively compiled and tested prebuilt darwin-arm64 binaries will also be provided for sharp.
Like @Dominoo I have exactly same issue with Gatsby.
Using nvm you will only run node only under rosetta and not the whole terminal
I accidentally came to this problem as I am trying to install
cordova-resglobally using npm. I tried some mentioned solutions up there and when I try to install it againnpm i -g cordova-resI get the same error.I am using mac M1 and node 14.x
Appreciate your help.
Sorry for getting off topic again!. There are still issues when installing node < 15, on arm… Please refer to this issue for example https://github.com/nvm-sh/nvm/issues/2350
When should we expect a fix for this ?
use an ubuntu 20.10 (maybe 20.04 works too) base, there are precompiled binaries for it
Try
brew install libvipsfirst and then it should work.I had all these issues and after all the fixes above it still didn’t work. I have now figured out the issue I was facing: I was running x86_64 brew to install the latest vips package. After removing x86_64 vips, I ran brew natively to install vips then after clearing my node_modules/lock file, sharp installed perfectly.
I was able to get it to work in the following ways with Node.js 15.3.0. Thanks @medhoover @kenips !
That’s what has been done for libvips.
Cross compiling the node library looks way more difficult. It might not be, but I didn’t manage to do it.
Missing those prebuilts isn’t a big deal that said, you most likely rely on dev tools being installed for other stuff (like homebrew itself, or any node gyp module)
you can build mac arm on intel, so infrastructure change is not really needed. Google Chromium describes it well: https://chromium.googlesource.com/chromium/src/+/master/docs/mac_arm64.md
@EMedina24 the “workaround” is to install vips via brew, or from source directly. How to do that is outlined in the thread above, for example, see https://github.com/lovell/sharp/issues/2460#issuecomment-768558230.
Once that’s installed
npm i sharpwill work fine. I just did it myself and it finished a few minutes ago (unlike what is implied here though, it took about 30mins to install on my machine).@abarisain thanks for the tip about
process.arch. Up until now I had been usingfile $(which node)which tells you the type of executable you get by runningnodein the terminal, your tip is more reliable though.any workaround for this yet. i cant get gatsby or gridsome to work without Sharp
Nothing strange here: homebrew doesn’t build fat (intel + arm) libraries and therefore you will run into issues as soon as install vips using brew
All of this will be solved when sharp ships an arm prebuilt, hang on tight!
@kalu-op For linuxmusl-arm64 prebuilds, please see https://github.com/lovell/sharp-libvips/issues/72
If running under rosetta, you don’t need to install vips yourself. Sharp will pull a prebuilt library
That said, I encounter crashes when running libvips under rosetta. If you do, Best course of action is unfortunately to wait for a patched nodejs.
Hi ! This was working fine on M1 with node 15.
But since the latest Big Sur release (11.2) node 15 is not working and we have to go back to use node 14 with rosetta (see https://github.com/nodejs/node/issues/37061)
and so i have once again this error when i try to launch a node program who use sharp (gatsbyjs) under node 14 with rosetta
I tried to install a x86_64 version of
vipswith the x86_64 version of brew (https://soffes.blog/homebrew-on-apple-silicon) but this don’t seems to work (i don’t know which version ofvipsis used).If someone has an idea ! Thanks
ok, so I have it working on my dev machine but I can’t ship that cause my customers are not going to have vips installed by brew?
I installed globally with
brew install libvipsand it works fine now,npm installworks as usual using the brew-installed version.@Dominoo Thanks for your tip. Actually how could you remove othet x86 deps?
brew uninstall *?Unfortunately I still can’t get it to install on my M1. I guess I am doing something wrong, but I installed libvips via homebrew as mentioned by @gpetrov (thanks for the hint). But when running npm install it ignores the global libvips installation.
I dug into the code node_modules/sharp/lib/libvips.js and there in the function useGlobalLibvips simply logged the minimum and global libvips version.
When I then run npm run install from within the node_modules/sharp directory I get:
Am I doing something wrong or has someone else run into this problem as well?
I have also fixed my
mach-o, but wrong architectureissue. I made 2 changes and therefore don’t know, what exactly helped me:Thanks a lot @cooknpop, @gpetrov and all others!
@iksent I succeed to solve the issue with
mach-o, but wrong architecture(even if not the cleanest solution). As my mac was new, I did a fresh clean-up of all my files and installed everything from scratch (mainly homebrew, nvm/node) making sure the architecture chosen was arm and not x86. Probably the issue was that at the beginning I downloaded node directly from the web, and this version is in x86 format, so the conflicts raised. I guess there is a simpler solution (I didn’t have the chance to check sharp folder from ./npm as I already had started the clean-up process at this point, another nightmare BTW).Said that, my suggestion: Install node directly with nvm from scratch in arm version and not from the web, with no other nodejs previously installed in the computer.
I hope it will help.
Your node_modules contain an old Mac x86 binary. You can delete them and do a fresh npm install
Thank you @medhoover and @kenips as well as @gpetrov for working on this. Just got myself a Mac Mini M1 and am struggling to get a project running.
Just wanted to add to @medhoover’s comment: the port name of
pkg-configispkgconfig. The port install command should besudo port install pkgconfig.