s-blog

sharp: Command failed 安装错误

ssssmy · 2026-05-28 · 1 min · Ubuntu

这个错误通常出现在 sharp 库安装时无法找到 libvips,这是 sharp 依赖的一个图像处理库。以下是一些解决方案:

1. 安装 libvips

在 Linux 系统上,可以尝试手动安装 libvips

sudo apt-get update
sudo apt-get install -y libvips-dev

2. 使用 --ignore-scripts 重新安装 sharp

可以尝试用 --ignore-scripts 参数重新安装 sharp,这样可以绕过一些预构建步骤:

npm install sharp --ignore-scripts

3. 清理 npm 缓存并重新安装依赖

有时候缓存问题也会导致安装失败:

npm cache clean --force
rm -rf node_modules
npm install

4. 使用 Node.js LTS 版本

某些 Node.js 版本与 sharp 依赖的编译过程不完全兼容,可以尝试切换到 LTS 版本的 Node.js。例如,Node.js 18 或 20。

5. 检查网络环境

日志中的 prebuild-install warn install Client network socket disconnected before secure TLS connection was established 提示有网络连接问题,可以检查网络环境是否稳定,或使用 VPN 连接后再重试安装。

原文链接:https://www.ssssmy.com/notes/sharp-command-failed-an-zhuang-cuo-wu