Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUIDE/FIX] installing on M1 (Apple Silicon) Macs: npm ERR! sharp Prebuilt libvips 8.10.5 binaries are not yet available for darwin-arm64v8 #204

Closed
madebyfabian opened this issue Mar 21, 2021 · 21 comments

Comments

@madebyfabian
Copy link
Sponsor

Hello there,
first of all, thank you all for the contributions to this plugin.
But I can't install it on a M1 (Apple Silicon Mac), since one of the Dependencies has to be built manually to make this work.

The Problem

When executing npm install --save-dev @nuxt/image

I get the following error stack:

npm ERR! code 1
npm ERR! path /Users/fabian/Desktop/code/madebyfabian-com/node_modules/sharp
npm ERR! command failed
npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
npm ERR! CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
npm ERR!   LIBTOOL-STATIC Release/nothing.a
npm ERR!   TOUCH Release/obj.target/libvips-cpp.stamp
npm ERR!   CXX(target) Release/obj.target/sharp/src/common.o
npm ERR! info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.5/libvips-8.10.5-darwin-arm64v8.tar.br
npm ERR! ERR! sharp Prebuilt libvips 8.10.5 binaries are not yet available for darwin-arm64v8
npm ERR! info sharp Attempting to build from source via node-gyp but this may fail due to the above error
npm ERR! info sharp Please see https://sharp.pixelplumbing.com/install for required dependencies
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | arm64
npm ERR! gyp info find Python using Python version 3.9.1 found at "/opt/homebrew/opt/[email protected]/bin/python3.9"
npm ERR! gyp info spawn /opt/homebrew/opt/[email protected]/bin/python3.9

and the package is not being installed.

Solution

  • You have to install "libvps" globally on your mac system to get this plugin to work on your development machine.
  • You need brew installed to do this.

Install gcc

The "libvps" depends on gcc, so do:

brew install --build-from-source gcc

Install XCode Build Tools CLI

Also required by "libvps"

xcode-select install

Install "vips"

brew install vips

Finally 🥳, install @nuxt/image

npm install --save-dev @nuxt/image

(or use yarn, if you want)


This solution works for me, but I am not an expert in all these dependencies, so if there is anything wrong, please correct it. I would suggest leaving this Issue open until e.g. the dependency get's updated and supports M1 Macs out of the box, so that anyone having the same problem can search and find this issue.

Copy link
Member

Thanks for the guide. I'm closing as this should now be fine since sharp 0.28.0 - see https://sharp.pixelplumbing.com/install#apple-m1.

@Gompje
Copy link

Gompje commented May 26, 2021

@madebyfabian

I'm still having issues getting things to run on my M1. Wonder if you can help me out?

Existing projects fail, but even a brand new one does when I add @nuxt/image. always on building Sharp.

When I install vips using brew I'm getting Package OpenEXR was not found. When I remove that I'm getting Prebuilt libvips 8.10.5 binaries are not yet available for darwin-arm64v8

I'm running all things under arm, so no rosetta. latests versions. The only diff I see with yours is that for some reason npm still wants to run python 2.7, despite having 3.9 and all things set to point to that.

And a diff node version:

gyp info using [email protected]
gyp info using [email protected] | darwin | arm64
gyp info find Python using Python version 2.7.16

Any idea what I'm missing? I feel like I'm running in circles 😖

@pi0
Copy link
Member

pi0 commented May 26, 2021

Hi @Gompje. Sorry hearing inconveniences. Have you tried node-gyp insulation: https://github.com/nodejs/node-gyp#on-macos

@Gompje
Copy link

Gompje commented May 26, 2021

// sorry for the long reply, I wrote this during my tests

hi @pi0, I followed the guide. There was indeed an error somehow with my xcode tools when running the acid test. That's resolved now :) sadly the errors still remain.

  • confirmed the xcode tools are installed and working, following the guide for Catalina. → Command Line Tools version: 12.5.0.0.1.1617976050
  • re-installed node-gyp globally, and the bundled version in npm
  • building the sharp module inside the node_modules, yields the same error chain. either vips is not found ../src/common.cc:24:10: fatal error: 'vips/vips8' file not found #include <vips/vips8>, or a dependency isn't found when vips is installed with brew Package OpenEXR was not found in the pkg-config search path. Perhaps you should add the directory containing OpenEXR.pc'`
  • confirmed arm bottle is runned → Pouring vips--8.10.6_3.arm64_big_sur.bottle.tar.gz

When I run this code in a Ubuntu x86 vm on unraid, everything works as expected. (just to be sure!) I noticed that I do run more recent versions of big sur, xcode, node, python and other packages AND that my npm found Python version seems to be stuck on stock 2.7. (which is honestly driving me crazy). Could it be all just the python config mess that is causing this?

// its not → when I add the --python=python3 flag to the npm install inside the sharp folder; it gives me the same errors.

any ideas? can the version of sharp be bumped to ^.0.28? in nuxt/ipx? I believe its set to ^.0.27.

if I do npm rebuild --verbose sharp it gives me the build errors. but when I do npm rebuild --verbose [email protected] it finishes with ok

When I add [email protected] to my test project, it works. but then when I add @nuxt/image it fails again on wanting to run sharp 0.27.x; in the ipx module. (given it wants 0.27.x)

can I force ipx to use v0.28? Any plans for a bump? For now I guess I can manually bump the version in its package.json locally and see how that goes. it doesn't matter if it does not run perfectly locally (for now), it just has to run.

@pi0
Copy link
Member

pi0 commented May 26, 2021

@Gompje Dependencies updated in [email protected]. It would be probably better if you also recreate lock file and node_modules . Would be nice if you can confirm if it fixed :)

@Gompje
Copy link

Gompje commented Jun 7, 2021

@pi0 finally have some time to test. this is a log.

  1. I added v0.4.11 with yarn
    → getting a fibers exit code 127 error
    You have not agreed to the Xcode license agreements ok. so there we have THAT again. sigh!
  • acid test reveals they are installed
  • running sudo xcodebuild -license and agree-ing
  • < repeat >
  1. I am now getting a lot of errors, more than my console can display. 🤔
    → maybe python 2 issue? yes.
  • running npm install --python=python3 inside the node_modules/sharp folder 🎉 gyp info ok ALLRIGHT!
  1. running dev env in root
    → build error, still defaults to python 2 off course 😠

  2. 🤷 trying npm instead
    → gives Nuxt fatal error: Something went wrong installing the "sharp" module .. Cannot find module '../build/Release/sharp.node' 🤔

  • running npm rebuild --verbose sharp --python=python3
  • run [email protected]
  • gyp info using [email protected]
  • npm ERR! gyp info using [email protected] | darwin | arm64
  • gyp verb find Python - version is "3.9.5"
  • gyp verb install version is good
  • ../src/common.cc:24:10: fatal error: 'vips/vips8' file not found

hmm seems like it's still stuck on v0.27? back to cleaning it is, and changing package.json manually. no go.

BUT
I added the module to a fresh nuxt js install and that seems to run fine now 😄
Given that a bunch of packages where outdated in the main project and even an auto upgrade of all failed, I will now move the content into a fresh install or just try to sync package.json with a fresh install.
Very hopeful v0.411 will work fine in the end.

For now it does seems to run fine on an empty project. Either way I will give feedback when I finished/or get stuck rebuilding.

Let's hope it was just old conflicting packages/code that prevented a decent upgrade.

@Gompje
Copy link

Gompje commented Jun 7, 2021

Update: seems to work 😄
→ synced the packages of the new install with my 'old' site. Now in the process of upgrade @nuxt/image to this new version; was still on 0.0.4!

But it works! 🎉 // with npm.
I did specify the sharp version in package.json, think it was from an earlier attempt. Left it, cannot harm things -- o contraire maybe

it seems to be that it was old node-sass that blocked it, and several eslint version mismatches b/c of to many packages that where upgraded.

@enigcreator
Copy link

install the latest version of node using
nvm install node
run npm install
solve the issue for me on Mac m1

@fabiolnm
Copy link

According to #204 (comment) and https://www.powerlifting.stream/posts/gatsby-m1/, I solved it by installing vips using homebrew:

brew install vips

@raulfdm
Copy link

raulfdm commented Dec 27, 2021

For the record, If you're trying to npm/yarn install a project and faced this problem, I was able to solve that by simply adding a resolution on my package.json to the sharp version which has compiled binary to M1:

{
  /* Other configs */
  "resolutions": {
    "sharp": "^0.29.0"
  }
}

https://sharp.pixelplumbing.com/install#apple-m1

@erkanercan
Copy link

Hello there, first of all, thank you all for the contributions to this plugin. But I can't install it on a M1 (Apple Silicon Mac), since one of the Dependencies has to be built manually to make this work.

The Problem

When executing npm install --save-dev @nuxt/image

I get the following error stack:

npm ERR! code 1
npm ERR! path /Users/fabian/Desktop/code/madebyfabian-com/node_modules/sharp
npm ERR! command failed
npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
npm ERR! CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
npm ERR!   LIBTOOL-STATIC Release/nothing.a
npm ERR!   TOUCH Release/obj.target/libvips-cpp.stamp
npm ERR!   CXX(target) Release/obj.target/sharp/src/common.o
npm ERR! info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.5/libvips-8.10.5-darwin-arm64v8.tar.br
npm ERR! ERR! sharp Prebuilt libvips 8.10.5 binaries are not yet available for darwin-arm64v8
npm ERR! info sharp Attempting to build from source via node-gyp but this may fail due to the above error
npm ERR! info sharp Please see https://sharp.pixelplumbing.com/install for required dependencies
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | arm64
npm ERR! gyp info find Python using Python version 3.9.1 found at "/opt/homebrew/opt/[email protected]/bin/python3.9"
npm ERR! gyp info spawn /opt/homebrew/opt/[email protected]/bin/python3.9

and the package is not being installed.

Solution

  • You have to install "libvps" globally on your mac system to get this plugin to work on your development machine.
  • You need brew installed to do this.

Install gcc

The "libvps" depends on gcc, so do:

brew install --build-from-source gcc

Install XCode Build Tools CLI

Also required by "libvps"

xcode-select install

Install "vips"

brew install vips

Finally 🥳, install @nuxt/image

npm install --save-dev @nuxt/image

(or use yarn, if you want)

This solution works for me, but I am not an expert in all these dependencies, so if there is anything wrong, please correct it. I would suggest leaving this Issue open until e.g. the dependency get's updated and supports M1 Macs out of the box, so that anyone having the same problem can search and find this issue.

Still worked for me for an old npm package, nice work!

elrumordelaluz added a commit to elrumordelaluz/outline-stroke-cli that referenced this issue Oct 6, 2022
@DaveFlashNL
Copy link

DaveFlashNL commented Oct 12, 2022

i've got a similar problem to this, while at this point vips has come out with arm mac support as of v8.10.6, one of my things is trying to npm i install an older version without macos arm support, only problem is, where can i force my install script to use a more current version such as 8.10.6 of sharp libvips?

@stolinski
Copy link

Just a small note on this issue. With an M1, using

	"resolutions": {
		"sharp": "^0.29.0"
	}

and latest versions of vite-imagetools@next, I was still seeing this issue. The only thing that fixed was the initial posted solution of installing vips via homebrew.

@DaveFlashNL
Copy link

i was able to fix it by adding --legacy-peer-deps to the node command

@erik-villegas
Copy link

My error code was slightly different since it included:

env: python: No such file or directory

Adding a symlink so the compile script could locate python fixed it for me:

ln -s -f /usr/local/bin/python3 /usr/local/bin/python

More info here: https://stackoverflow.com/questions/71468590/env-python-no-such-file-or-directory-when-building-app-with-xcode

@hoonsubin
Copy link

hoonsubin commented Apr 21, 2023

When I run the command brew install --build-from-source gcc, I get the following error:

Error: An exception occurred within a child process:
  NoMethodError: undefined method `issues_url' for nil:NilClass

Searching this error only results in Ruby-related questions (which makes sense, I guess), but I'm not sure what I should do as someone installing the package. The closest answer I got was https://github.com/orgs/Homebrew/discussions/4404
I can try without the --build-from-source flag, but I'm not sure why we need that in this case.
Any suggestions?

@IslamWahid
Copy link

The official docs shall be updated as it says on M1
Prebuilt sharp and libvips binaries have been provided for macOS on ARM64 since sharp v0.29.0
but that's not the case am getting the error on M2 ARM64 and had to run brew install vips in order to get the package installed

@bzpassersby
Copy link

For the record, If you're trying to npm/yarn install a project and faced this problem, I was able to solve that by simply adding a resolution on my package.json to the sharp version which has compiled binary to M1:

{
  /* Other configs */
  "resolutions": {
    "sharp": "^0.29.0"
  }
}

https://sharp.pixelplumbing.com/install#apple-m1

Thanks! Adding a resolution for sharp works perfectly for me.

@Histamina
Copy link

For the record, If you're trying to npm/yarn install a project and faced this problem, I was able to solve that by simply adding a resolution on my package.json to the sharp version which has compiled binary to M1:

{
  /* Other configs */
  "resolutions": {
    "sharp": "^0.29.0"
  }
}

https://sharp.pixelplumbing.com/install#apple-m1

I don't have enough words to thank you. <3

@DaveFlashNL
Copy link

now i get a new error Package 'vips' requires 'libhwy >= 1.0.5' but version of libhwy is 1.0.4

@ahmad-elafify-pci
Copy link

For the record, If you're trying to npm/yarn install a project and faced this problem, I was able to solve that by simply adding a resolution on my package.json to the sharp version which has compiled binary to M1:

{
  /* Other configs */
  "resolutions": {
    "sharp": "^0.29.0"
  }
}

https://sharp.pixelplumbing.com/install#apple-m1

i think i love you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests