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

Next.js如何在next.config.js中配置多个图片主机名?

解决Next.js Image组件remotePatterns配置错误

你的问题出在remotePatterns的配置规则上:每个remotePattern对象里的hostname必须是字符串类型,不能用数组同时放多个域名。

修正后的代码如下:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'images.unsplash.com'
      },
      {
        protocol: 'https',
        hostname: 'hydeparkwinterwonderland.com'
      },
      {
        protocol: 'https',
        hostname: 'wembleypark.com'
      }
    ]
  }
}

module.exports = nextConfig

把每个域名拆成独立的remotePattern对象,放进remotePatterns数组里,就能满足Next.js的配置要求,解决报错。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 17:50:44