
1 min read95 words
INVALID_IMAGE_OPTIMIZE_REQUEST 临时解决
Technology
Technology
Productivity
“INVALID_IMAGE_OPTIMIZE_REQUEST” 是 Vercel 的图片优化接口返回的通用报错,表示请求参数不合法或被拦截。
临时解决方案,在 next.config.js 里设置 images.unoptimized: true
import type { NextConfig } from "next"; const nextConfig: NextConfig = { /* config options here */ images: { unoptimized: true, // 禁用图像优化 }, }; export default nextConfig;
常见原因与解决办法如下:
最常见原因与对应修复
-
手写了优化接口但参数不完整/未编码
- 若你直接请求 /_next/image 或 /_vercel/image,必须包含且正确设置:
- url:绝对地址,且使用 encodeURIComponent 编码
- w:数字宽度(建议使用 Next 配置中的允许尺寸)
- q:1–100 的整数
建议不要手写该 URL,Next.js 用 Image 会自动生成正确参数。
- 若你直接请求 /_next/image 或 /_vercel/image,必须包含且正确设置:
-
未在 next.config.js 里放行外链域名
import type { NextConfig } from "next"; const nextConfig: NextConfig = { /* config options here */ images: { // unoptimized: true, // 禁用图像优化 domains: ['cdn.pixabay.com','unsplash.com'] }, }; export default nextConfig; -
重写/代理导致查询参数丢失或路由被拦截
- vercel.json 或 next.config.js 的 rewrites/redirects、外层 Nginx/Cloudflare 若“忽略查询字符串”,会把 w/q/url 丢掉,触发该错误。
- 确保不重写/缓存拦截 /_next/image 或 /_vercel/image,且必须保留查询参数。
-
width/quality 值非法
- w 必须是数字,且对于 Next.js 通常会落在 deviceSizes/imageSizes 集合中(Image 会自动处理)。
- q 必须是 1–100 的整数。