安装 sharp 报错

45 阅读1分钟
.../sharp@0.32.6/node_modules/sharp install$ (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
│ sharp: Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.14.5/libvips-8.14.5-darwin-arm64v8.tar.br
│ sharp: Installation error: connect ETIMEDOUT 20.205.243.166:443
│ sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
└─ Failed in 1m 17.9s at /xxx/node_modules/.pnpm/sharp@0.32.6/node_modules/sharp

解决方案

# 设置sharp使用国内镜像
pnpm config set sharp_binary_host "https://npmmirror.com/mirrors/sharp"
pnpm config set sharp_libvips_binary_host "https://npmmirror.com/mirrors/sharp-libvips"

# 然后重新安装
pnpm remove sharp
pnpm add sharp