nextjs iamge 中的 src 属性无效

问题描述 投票:0回答:1

我正在尝试从后端获取 udemy 课程,但当我使用图像组件时,我不断收到此错误。 错误:next/image 上的 src 属性 (

https://img-b.udemycdn.com/course/750x422/1943926_e313.jpg
) 无效,主机名“img-b.udemycdn.com”未在您的图像下配置
next.config.js
这是下一个.config.js

const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  optimizeFonts: true,
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'img-b.udemycdn.com',
        pathname: '**',
      },
    ],
  },
};

module.exports = nextConfig;
next.js nextjs-image
1个回答
0
投票

pathname
留空,并添加一个空字符串作为
port
属性,如下所示:

const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  optimizeFonts: true,
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'img-b.udemycdn.com',
        port: '',
      },
    ],
  },
};

© www.soinside.com 2019 - 2024. All rights reserved.