我正在尝试使用我的 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 处理器是
arm64
。 here发布了一个解决方案,需要将终端架构更改为arch -x86_64 zsh
,但我不想这样做。
所以,这就是我能够发现的解决方法(错误中也提到了一些步骤):
rm -rf node_modules/sharp
npm install --arch=x64 --platform=darwin sharp
对我来说,我所要做的就是:
brew reinstall vips
然后对项目进行全新安装。
我的答案与将功能部署到 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 运行一个项目时,使用的节点版本不兼容。
当项目实际需要版本时,我尝试使用版本 16 运行项目 <=14.
因此,如果有人遇到此问题,可能值得检查节点版本
这对我有用
https://sharp.pixelplumbing.com/install
npm install --platform=darwin --arch=x64 sharp
npm rebuild --platform=darwin --arch=arm64 sharp
出于某种原因,我通过删除
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.
我今天在本地启动 Gatsby 应用程序时遇到此错误。恢复到我在安装最初的 Gatsby 应用程序时使用的 Node 版本有助于我克服它。从节点 v16 切换到 v14.20。
我在 pod 安装时遇到了同样的问题。不幸的是,上述答案都不起作用。对我来说解决这个问题的是使用 NPM 重建 Sharp。
npm rebuild sharp
在 MacO 上测试。更新 MacOs 版本后会发生这种情况。尝试如下
nvm uninstall 14
nvm install 14
yarn
如果出现错误
nvm: Cannot uninstall currently-active node version
。尝试切换到另一个节点版本并卸载您想要使用的版本,然后返回到您想要使用的版本。
例如:
// 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
我在使用 Sharp 构建的另一个软件包时遇到此错误,需要卸载 VIPS
npm uninstall MY_PACKAGE
brew uninstall vips
npm install MY_PACKAGE