strapi项目 yarn 报错:/node_modules/sharp: Command failed.

部署了strapi的服务器内存满了,优化清空的时候删了些东西,最后发现,竟导致整个Strapi项目构建失败,最后发现是因为删除了/root/.npm导致的。

问题现场:删除.npm后的灾难性报错

当在服务器上执行完rm -rf ~/.npm以清理磁盘空间,过了几天Strapi项目修改需要重启的时候,在项目中运行yarn install,终端突然抛出一连串红色错误:

bash

复制

下载

less 复制代码
"@strapi/strapi > @strapi/admin > use-context-selector@1.4.1" has unmet peer dependency "scheduler@>=0.19.0".
warning " > strapi-plugin-transformer@3.1.2" has unmet peer dependency "lodash@^4.17.21".
warning " > strapi-plugin-transformer@3.1.2" has unmet peer dependency "yup@^0.32.9".
warning " > styled-components@5.3.3" has unmet peer dependency "react-is@>= 16.8.0".
warning "styled-components > babel-plugin-styled-components > @babel/plugin-syntax-jsx@7.27.1" has unmet peer dependency "@babel/core@^7.0.0-0".
[5/5] Building fresh packages...
[6/10] ⠁ sharp
[10/10] ⠁ sqlite3
[8/10] ⠁ better-sqlite3
[9/10] ⠁ sharp
error /home/service/cms/web_tsinghua_cms/node_modules/@strapi/plugin-upload/node_modules/sharp: Command failed.
Exit code: 1
Command: (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
Arguments: 
Directory: /home/service/cms/web_tsinghua_cms/node_modules/@strapi/plugin-upload/node_modules/sharp
Output:
...

尽管网络通畅,sharp模块安装依然失败,导致整个Strapi项目无法启动。更令人困惑的是,同一命令在其它服务器却执行正常。


一、解剖问题:为什么删除.npm会引发sharp安装失败?

1. npm缓存的核心作用

~/.npm目录是npm的全局缓存仓库,存储着:

  • 下载过的所有包(_cacache目录)
  • 预编译的二进制模块(如sharp的本地编译版本)
  • 包元数据及签名信息8

当执行npm installyarn install时,系统优先检查缓存,若存在匹配版本则直接使用缓存包,避免重复下载和编译6。

2. Sharp模块的特殊性

Sharp是一个高性能图像处理库:

  1. 依赖预编译的C++库(libvips)
  2. 安装时会下载平台特定的二进制文件(Linux/macOS/Windows)
  3. 若缓存不存在,自动触发本地编译(需Python/C++编译环境)1

二、终极修复方案

直接从另一个服务器拷贝了一份具有相同环境的 /root/.npm,并且把服务的gcc、g++、glibc都重新升级以后好了。

相关推荐
Setsuna_F_Seiei2 小时前
前端转型 Agent 开发 05 之 Agent Hooks 与 Checkpointer(让 Agent 从全自动转变人为可掌控)
前端·agent·ai编程
百万蹄蹄向前冲4 小时前
风扇转了一晚上MVP专家团翻车事故
前端·人工智能
默_笙4 小时前
🏛 给 AI 配一间办公室:Harness Engineering 六大模块与它的实现
前端·javascript
linux_cfan5 小时前
videojs v10 源代码系列解读:14 · 谓词守卫:在运行时安全地调用能力
前端·javascript·音视频
kyriewen6 小时前
我扒了 10,221 条 JD:腾讯技术岗 75% 在要 AI
前端·人工智能·ai编程
郑州光合科技余经理6 小时前
同城外卖小程序开发:下单成功后,后台导出能不能对上用户端状态
开发语言·前端·git·后端·uni-app·php·ai编程
IT_陈寒7 小时前
Vue的响应式让我熬到凌晨三点,原来漏了这个小细节
前端·人工智能·后端
Blanche15007 小时前
利用 RAG 为答疑机器人扩展知识范围
前端
天若有情6737 小时前
【纯前端小工具】公历生日转农历,批量查询每年农历生日对应的公历日期(GitHub Pages在线直接用)
前端·javascript·github pages·农历转换·lunisolar·网页小工具
SoonITer7 小时前
怎样构建一个 Agent-friendly 的网站
前端·agent