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
相关产品推荐
相关产品推荐

