0

I am having an error and am unable to fetch the image from the API and they are showing me an error although it works on img tag but when i replace the this with NextJS Image tag then it is showing me this error.

    import React, { useState, useEffect } from "react";
    import { useDispatch, useSelector } from "react-redux";
    import Image from 'next/image';
    
    const ChannelDetailCard = ({
      data,
      id,
      channel_image,
      channel_name,
    
    }) => {
    
      return (
        <>
            <div className="ml-0 flex justify-center lg:flex lg:ml-10">
              <Image
                className="w-64 h-64 object-cover rounded"
                src={channel_image}
                objectFit="contain"
                layout='fill'
              />
           </div>  
         </> 
             ) 
     }
    }

Here is the Error which i gets while running this code.(Sample) enter image description here

Wasiq Ali
  • 26
  • 5

2 Answers2

2

Since, you're loading images from external source, different domain than the current application domain, you need to explicitly add all the domains of the images that you're loading in the next.config.js file as mentioned here

Edit your next.config.js file and add:

module.exports = {
  images: {
    domains: ['example.domain.com'],
  },
}

Make sure to replace example.domain.com with the domain name of your image source. After saving reload and it should work.

OMi Shah
  • 5,768
  • 3
  • 25
  • 34
1

in your nextjs config

u have to add the hostename of the website u bring images from
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
images: {
domains: ["********.com"],
},
};

module.exports = nextConfig;

if u have multiple origins, then u have to add them like this domains:["abc.com","xyz.com"]

person zen
  • 91
  • 1
  • 4