You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js 13.0.5中Next/Image已配置外部主机仍报错求助

解决Next.js 13.0.5中Next/Image加载CloudFront图片的配置问题

针对你遇到的已配置remotePatterns但仍报错的情况,按以下步骤排查:

  • 重启开发服务器:修改next.config.js后,必须重启Next.js开发服务才能让新配置生效,这是最容易忽略的点。
  • 简化remotePatterns配置:去掉port字段(HTTPS默认使用443端口,无需显式指定),修改后的配置如下:
    const nextConfig = {
      reactStrictMode: true,
      swcMinify: true,
      images: {
        remotePatterns: [
          {
            protocol: "https",
            hostname: "d2ss8eaptdxs3l.cloudfront.net",
            pathname: "/**",
          },
        ],
      },
    }
    
    module.exports = nextConfig
    
  • 尝试使用domains配置:虽然remotePatterns是12.3.0+推荐的方式,但部分场景下domains配置更稳定,替换成以下配置试试:
    const nextConfig = {
      reactStrictMode: true,
      swcMinify: true,
      images: {
        domains: ["d2ss8eaptdxs3l.cloudfront.net"],
      },
    }
    
    module.exports = nextConfig
    
  • 清除缓存并重启:删除项目根目录下的.next文件夹,清除缓存后再启动开发服务器,避免旧配置残留。
  • 确认配置文件位置:确保next.config.js在项目根目录(而非src子目录),否则Next.js无法读取到配置。

另外注意到你代码中图片路径是profile_pictures(下划线),但报错信息里的路径是profile-pictures(横杠),虽然pathname: "/**"会匹配所有子路径,但建议保持代码中路径与实际文件路径一致,避免其他潜在问题。

内容的提问来源于stack exchange,提问作者Hajimaru

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 08:15:32