Next.js next/image组件报错:image.tmdb.org未配置,配置后仍无效
解决Next.js
next/image 主机名未配置问题 问题原因
你配置的pathname过于严格,仅匹配/t/p/original路径,但TMDB图片存在多种尺寸路径(如/t/p/w500、/t/p/w300等),导致部分图片路径无法匹配规则,触发报错。
修复步骤
修改
next.config.js的remotePatterns配置
将pathname改为通配格式,覆盖所有TMDB图片路径:const nextConfig = { images: { remotePatterns: [ { protocol: 'https', hostname: 'image.tmdb.org', port: '', pathname: '/t/p/**', // 用通配符匹配所有图片路径 }, ], }, }; module.exports = nextConfig;重启Next.js开发服务器
修改next.config.js后必须重启服务,新配置才会生效。验证图片src格式
确保next/image的src是完整的HTTPS链接,例如:https://image.tmdb.org/t/p/original/your-image-id.jpg,不能使用相对路径。
内容的提问来源于stack exchange,提问作者bhuws
相关产品推荐
相关产品推荐

