Home > Software design >  I have an error while customizing my default next config js file . I have tried in multiple ways but
I have an error while customizing my default next config js file . I have tried in multiple ways but

Time:09-16

As you can see that I want to add my custom configuration in next.config.js . But it throws and error of invalid src prop . I have tried this in multiple ways but it always throws an error.

// Default Configuration
    /** @type {import('next').NextConfig} */
    const nextConfig = {
      reactStrictMode: false,
      swcMinify: true,
      image: {
        domains: ["links.papareact.com", "image.tmdb.org"],
      },
    };
    
    module.exports = nextConfig;
    
    //Configuration I want to add in this file
    module.exports = {
      images: {
        domains: ["links.papareact.com", "image.tmdb.org"],
      },
    };

CodePudding user response:

Two things. The first export ist correct, you just have a typo. But you are defining the export again. You can just have one module.exports:

// Default Configuration
/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: false,
  swcMinify: true,
  images: {
    domains: ["links.papareact.com", "image.tmdb.org"],
  },
};

module.exports = nextConfig;

Note its images not image. You might want to checkout the loader configuration: https://nextjs.org/docs/api-reference/next/image#loader-configuration

CodePudding user response:

I think you need a loader for images here

    const myLoader=({src})=>{
     return `${path}`;
    }

src, in that case, is what you add in config

<Image loader={myLoader} ...
  • Related