You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

M1芯片Mac Big Sur系统执行npm install安装sharp报错求助

macOS环境安装sharp依赖包失败问题

我在项目中安装sharp依赖包时,执行npm i和npm install sharp命令均返回相同的sharp相关报错,我已经尝试过全局和本地安装libvips,也查阅了所有相关的问题讨论帖,还是没找到可行的解决方案,希望能得到大家的帮助。

完整报错日志

rosetta错误:/var/db/oah/223263137464320_223263137464320/e6ddd63cd8fd3b7ef226e2cad9a1bead9d7f41f60d7ece6edd0cdcc0c33c97c6/libxcrun.dylib.aot:代码签名补充附件失败:1
gyp ERR! 构建错误
gyp ERR! 栈错误:`make`执行失败,退出码:null
gyp ERR! 栈     at ChildProcess.onExit (/Users/elektra.murphy/.nvm/versions/node/v11.11.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! 栈     at ChildProcess.emit (events.js:197:13)
gyp ERR! 栈     at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)
gyp ERR! 系统 Darwin 20.6.0
gyp ERR! 命令 "/Users/elektra.murphy/.nvm/versions/node/v11.11.0/bin/node" "/Users/elektra.murphy/.nvm/versions/node/v11.11.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! 当前工作目录 /Users/elektra.murphy/Desktop/Projects/node_modules/sharp
gyp ERR! node版本 v11.11.0
gyp ERR! node-gyp版本 v3.8.0
gyp ERR! 执行失败
npm WARN enoent 无此文件或目录,打开'/Users/elektra.murphy/Desktop/Projects/package.json'失败
npm WARN 无项目描述
npm WARN 无仓库字段
npm WARN 无README文档
npm WARN 无许可证字段

npm ERR! 错误代码 ELIFECYCLE
npm ERR! 错误号 1
npm ERR! sharp@0.23.2 安装脚本执行失败:`(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)`
npm ERR! 退出状态 1
npm ERR! 
npm ERR! sharp@0.23.2 安装脚本执行失败。
npm ERR! 该问题大概率不是npm导致的,上方可能有更多相关日志输出。

npm ERR! 完整运行日志可在以下路径找到:
npm ERR!     /Users/elektra.murphy/.npm/_logs/2021-10-12T08_24_48_579Z-debug.log

可行解决方案参考

根据报错信息中的rosetta相关错误以及环境信息,可以按以下步骤逐一排查:

  • 优先升级Node版本到v14及以上的LTS版本,你当前使用的Node v11.11.0属于老旧版本,在M1系列芯片的Mac上运行需要通过rosetta转译,极易出现签名、构建类兼容问题,v14+的Node版本原生支持arm64架构,无需转译运行,可以解决大部分依赖构建问题。
  • 清理缓存后重新安装,依次执行以下命令:
    npm cache clean --force
    rm -rf node_modules
    rm package-lock.json
    npm install sharp --unsafe-perm
    
  • 若仍安装失败,可调用本地已安装的libvips进行构建,执行安装命令前先设置环境变量:
    export SHARP_IGNORE_GLOBAL_LIBVIPS=0
    npm install sharp
    
  • 临时方案可以右键点击终端图标,选择「显示简介」后勾选「使用Rosetta打开」,重启终端后再执行安装命令。

内容的提问来源于stack exchange,提问作者Elektra Murphy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 23:27:04