本文摘要
文章记录了 pnpm 安装 sharp 时因无法从 GitHub 下载 libvips 二进制包而报错的问题,典型表现是安装脚本执行失败并提示连接被拒绝。解决办法是通过 pnpm config 将 sharp 及其 libvips 的二进制下载地址改为 npmmirror 国内镜像源,适合国内网络环境下遇到同类依赖安装失败的开发者参考。
报错内容如下:
PS F:\myproject> pnpm iWARN 4 deprecated subdependencies found: @esbuild-kit/core-utils@3.3.2, @esbuild-kit/esm-loader@2.6.5, glob@7.2.3, inflight@1.0.6Packages: +946+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Progress: resolved 1045, reused 942, downloaded 5, added 946, donenode_modules/.pnpm/esbuild@0.23.1/node_modules/esbuild: Running postinstall script, done in 660msnode_modules/.pnpm/esbuild@0.18.20/node_modules/esbuild: Running postinstall script, done in 534msnode_modules/.pnpm/esbuild@0.19.12/node_modules/esbuild: Running postinstall script, done in 508msnode_modules/.pnpm/sharp@0.32.6/node_modules/sharp: Running install script, failed in 348ms.../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-win32-x64.tar.br│ sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies└─ Failed in 348ms at F:\myproject\node_modules\.pnpm\sharp@0.32.6\node_modules\sharp ELIFECYCLE Command failed with exit code 1. WARN 4 deprecated subdependencies found: @esbuild-kit/core-utils@3.3.2, @esbuild-kit/esm-loader@2.6.5, glob@7.2.3, inflight@1.0.6Packages: +946+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.../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: Installation error: connect ECONNREFUSED 127.0.0.1:443│ sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies└─ Failed in 326ms at F:\myproject\node_modules\.pnpm\sharp@0.32.6\node_modules\sharpnode_modules/.pnpm/esbuild@0.19.12/node_modules/esbuild: Running postinstall script, done in 275msnode_modules/.pnpm/esbuild@0.18.20/node_modules/esbuild: Running postinstall script, done in 293ms ELIFECYCLE Command failed with exit code 1.解决方案:
pnpm config set sharp_binary_host=https://npmmirror.com/mirrors/sharppnpm config set sharp_libvips_binary_host=https://npmmirror.com/mirrors/sharp-libvips