# 错误：`next/image` 上的 src prop 无效，主机名 "example.com" 未在 images.remotePatterns 中配置

- **ID:** `nextjs/next-image-unconfigured-hostname`
- **领域:** nextjs
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

Next.js 的 Image 组件要求在 next.config.js 的 images.remotePatterns 中明确允许外部图片主机名，以确保安全和优化；否则会抛出此错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Next.js 13.0.0 | active | — | — |
| Next.js 14.0.0 | active | — | — |
| Next.js 14.2.0 | active | — | — |

## 解决方案

1. ```
   Add the hostname to next.config.js: 'images: { remotePatterns: [{ protocol: "https", hostname: "example.com" }] }'
   ```
2. ```
   If using Next.js 14+, use the 'images.unoptimized: true' config to disable all image optimization (not recommended for production).
   ```
3. ```
   For multiple hostnames, add each one: 'images: { remotePatterns: [{ protocol: "https", hostname: "example.com" }, { protocol: "https", hostname: "cdn.example.com" }] }'
   ```

## 无效尝试

- **** — images.domains is deprecated since Next.js 13; images.remotePatterns is the required configuration. (70% 失败率)
- **** — remotePatterns requires explicit protocol and hostname; wildcards must be in the hostname field, not as a string pattern. (60% 失败率)
- **** — This bypasses optimization but still requires the hostname to be configured for security; the error persists. (80% 失败率)
