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

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)



Solution 1:[1]

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

Solution 2:[2]

For me, all I had to do was:

brew reinstall vips

then do a clean install of the project.

Solution 3:[3]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lucas Ramos
Solution 2 PeeKey
Solution 3 Patrik Rikama-Hinnenberg