'darwin-arm64v8' binaries cannot be used on the 'darwin-x64' platform
Asked Answered
M

11

14

I am trying to deploy functions to firebase using my Mac M1, for which it was required to do an npm install to install packages in node_modules/. I am getting this error:

Error: 'darwin-arm64v8' binaries cannot be used on the 'darwin-x64' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the 'darwin-x64' platform.
    at Object.hasVendoredLibvips (/Users/ali/Desktop/tajir/backend-mvp/appengine/back-end-flex/node_modules/sharp/lib/libvips.js:80:13)
    at Object.<anonymous> (/Users/ali/Desktop/tajir/backend-mvp/appengine/back-end-flex/node_modules/sharp/lib/constructor.js:7:22)
    at Module._compile (internal/modules/cjs/loader.js:1136:30)
    at Module._compile (pkg/prelude/bootstrap.js:1394:32)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1156:10)
    at Module.load (internal/modules/cjs/loader.js:984:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1024:19)
    at Module.require (pkg/prelude/bootstrap.js:1338:31)
    at require (internal/modules/cjs/helpers.js:72:18)

Maltz answered 17/8, 2021 at 8:37 Comment(0)
M
24

Usually someone having a Mac M1 would have this issue. The Mac M1 processor is arm64. There was a solution posted here which requires to change terminal architecture to arch -x86_64 zsh which I did not want to do.

So, that's the workaround I was able to discover (some of the steps also mentioned in the error):

rm -rf node_modules/sharp
npm install --arch=x64 --platform=darwin sharp
Maltz answered 17/8, 2021 at 8:37 Comment(6)
How does this work with something like electron-universal which requires support for both x86_64 and arm64?Accuse
I did this terminal architecture change that you mentioned cause I needed to run pentaho from M1 Mac. How can I undo this? I deleted the newly created intel terminal profile but it does not solved the error.Bailsman
@Accuse the version you should install for @electron/universal should depend on the architecture of your computer's processor, as this is just a package to make apps for both platforms. I am assuming you're asking whether you should install the arm64 version or x86 etc.Maltz
@Bailsman If the architecture of your processor was arm64 before, then you can undo the thing using the same command you used to make it x86, but you must write arm64 instead. Unfortunately the website link I gave no longer exists :-(Maltz
Thanks for mentioning that @AliSajjad. I just fixed the link.Accuse
For ARM CPUs, such as M1 use this: npm install --cpu=arm64 --os=darwin sharp Official docInverness
S
8

For me, all I had to do was:

brew reinstall vips

then do a clean install of the project.

Subsidy answered 19/10, 2021 at 16:34 Comment(4)
Hi, what is vips?Shadowy
In my case the error message contained something about "vips" and reinstalling it helped me.Cystectomy
@Shadowy "A fast image processing library with low memory needs." github.com/libvips/libvips formulae.brew.sh/formula/vipsSubsidy
brew reinstall vips helped me (mac m1 pro), thanksExpletive
S
7

this works for me

https://sharp.pixelplumbing.com/install

npm install --platform=darwin --arch=x64 sharp
npm rebuild --platform=darwin --arch=arm64 sharp
Subpoena answered 27/3, 2023 at 4:49 Comment(0)
C
4

My answer is not related to deploying functions to firebase, but I had that exact same error:

Error: 'darwin-x64' binaries cannot be used on the 'darwin-arm64v8' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the 'darwin-arm64v8' platform.

when I tried to run a project with a mac M1 using a version of node that was incompatible.

I tried to run the project with version 16 when the project actually require version <=14.

So if anyone has this problem might be worth checking the node version

Cotopaxi answered 28/2, 2022 at 11:42 Comment(1)
Do you mean the required version of node might be <=14 or you're talking about the package?Maltz
K
2

For some reason I got it fixed with removing node_modules and installing them again.

Error: 'darwin-x64' binaries cannot be used on the 'darwin-arm64v8' platform. 
  Please remove the 'node_modules/sharp' directory and run 'npm install' on the 
  'darwin-arm64v8' platform.
Kev answered 15/11, 2021 at 13:49 Comment(0)
A
1

I had the same problem which occured on a pod install. Unfortunately none of the above answers worked. What fixed the issue for me was rebuilding sharp with NPM.

npm rebuild sharp
Adenoidectomy answered 30/3, 2023 at 7:9 Comment(0)
B
1

Tested on MacOs. This happened after you update MacOs version. Try as below

nvm uninstall 14
nvm install 14
yarn

Notes.

If you got error nvm: Cannot uninstall currently-active node version. Try to switch to another node version and uninstall version you want to, then go back to version you want to use.

EX:

// Temporary switch to another version
nvm install 15

// Now you can uninstall version 14
nvm uninstall 14

// Reinstall version 14
nvm install 14

// Everything should work now.
yarn
Borgia answered 20/4, 2023 at 8:21 Comment(0)
P
0

I got this error today spinning up a Gatsby app locally. Reverting to the Node version that I used when installing the originally Gatsby application worked for me to get past it. Switched from Node v16 to v14.20.

Prude answered 31/10, 2022 at 20:29 Comment(0)
F
0

I was getting this error with another package built on sharp and needed to uninstall VIPS

npm uninstall MY_PACKAGE
brew uninstall vips
npm install MY_PACKAGE
Farriery answered 5/10, 2023 at 18:49 Comment(0)
R
0

For anyone looking for a yarn solution, here it is after some hours of searching:

rm -rf node_modules/sharp
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm_config_arch=arm64 npm_config_platform=darwin yarn add sharp

This is the platform and arch for mac silicon. You may need to change it if you're on different hardware. The right ones will be named in the error log

Rankle answered 16/10, 2023 at 11:45 Comment(0)
K
0

This works for me:yarn add sharp --ignore-engines with macos and node18

Kurman answered 4/3, 2024 at 3:21 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.