# 错误：next/image 上的 width 属性无效。宽度必须为正数且小于或等于图像的原始宽度（1920）。

- **ID:** `nextjs/invalid-image-width-attribute`
- **领域:** nextjs
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

next/image 组件的 width 属性设置为大于图像原始宽度的值，或为零/负数。Next.js 强制要求 width 不能超过原始图像尺寸，以防止未经明确配置的放大。

## 版本兼容性

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

## 解决方案

1. ```
   Set the width prop to the image's actual intrinsic width or smaller. Use the fill prop with sizes if you need to stretch beyond intrinsic dimensions.
   ```
2. ```
   Use the unoptimized prop to bypass Next.js image optimization, which also relaxes dimension validation.
   ```

## 无效尝试

- **Setting width to a very large number like 9999 to avoid responsive issues** — Next.js validates width against the actual image dimensions. Using a value larger than intrinsic width triggers this error. (90% 失败率)
- **Omitting width and height props entirely** — next/image requires either width/height or fill prop. Omitting them results in a different error about missing dimensions. (80% 失败率)
- **Using CSS to override the width after setting it incorrectly** — The validation happens at build/render time before CSS is applied. CSS overrides don't prevent the error. (85% 失败率)
