'darwin-arm64v8' 二进制文件不能在 'darwin-x64' 平台上使用

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

我正在尝试使用我的 Mac M1 将功能部署到 firebase,为此需要执行 npm install 以在 node_modules/ 中安装包。 我收到此错误:

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)

通常拥有 Mac M1 的人都会遇到这个问题。 Mac M1 处理器是 arm64here 发布了一个解决方案,它需要将终端架构更改为 arch -x86_64 zsh,但我不想这样做。

所以,这就是我能够发现的解决方法(错误中也提到了一些步骤):

rm -rf node_modules/sharp
npm install --arch=x64 --platform=darwin sharp

对我来说,我所要做的就是:

brew reinstall vips

然后对项目进行全新安装。

出于某种原因,我通过删除 node_modules 并重新安装它们来修复它。

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.

我的回答与将函数部署到 firebase 无关,但我遇到了完全相同的错误:

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.

当我尝试 运行 一个带有 mac M1 的项目时,使用的节点版本不兼容。

当项目实际需要版本 <=14 时,我尝试 运行 版本 16 的项目。

所以如果有人遇到这个问题可能值得检查节点版本