# 错误：对 URL '...' 的图像优化失败，状态码 500。内部错误：sharp 未安装。

- **ID:** `nextjs/image-optimization-internal-server-error`
- **领域:** nextjs
- **类别:** module_error
- **错误码:** `500`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Next.js 图像优化依赖 'sharp' 库进行服务器端图像处理。当 sharp 缺失或安装失败（例如在某些架构或无服务器环境中）时，优化端点返回 500 错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 13.4.0 | active | — | — |
| 13.5.0 | active | — | — |
| 14.0.0 | active | — | — |
| 14.2.0 | active | — | — |
| 15.0.0 | active | — | — |

## 解决方案

1. ```
   Install sharp explicitly as a production dependency: npm install sharp@latest. Ensure your deployment platform supports sharp (e.g., Vercel, Netlify). For serverless, use next.config.js: experimental: { optimizePackageImports: ['sharp'] }.
   ```
2. ```
   If sharp cannot be installed, set images.unoptimized: true in next.config.js to disable all image optimization globally, or use a third-party image CDN provider configured via images.loader.
   ```

## 无效尝试

- **Reinstalling sharp with npm install sharp without specifying the correct platform binary** — The default installation may try to build from source, failing on systems without C++ build tools. It's better to use --ignore-scripts or install platform-specific binaries. (60% 失败率)
- **Setting unoptimized: true on every Image component as a global workaround** — This disables all image optimization, leading to large unoptimized images, slower page loads, and potential layout shifts. It's a performance regression. (30% 失败率)
