小编Enb*_*eur的帖子

Next.js - 我可以在 next.config.js 中配置多个图像主机名吗?

我在 next.config.js 中编写了下面的代码

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

module.exports = nextConfig
Run Code Online (Sandbox Code Playgroud)

但它会抛出这样的错误:

- The value at .images.remotePatterns[0].hostname must be a string but it was an array.

See more info here: https://nextjs.org/docs/messages/invalid-next-config
Run Code Online (Sandbox Code Playgroud)
Error: Invalid images.remotePatterns values:
{"protocol":"https","hostname":["images.unsplash.com","hydeparkwinterwonderland.com","wembleypark.com"]}

remotePatterns value must follow format { protocol: 'https', hostname: 'example.com', port: '', pathname: '/imgs/**' }.
See more info here: https://nextjs.org/docs/messages/invalid-images-config
Run Code Online (Sandbox Code Playgroud)

正在寻找答案,我是新手,请耐心等待

next.js

5
推荐指数
1
解决办法
5586
查看次数

标签 统计

next.js ×1