skip to Main Content

I want to get images from cdn, but next reports error hostname **** is not configured under images in your next.config.js.According to the next official website, I added the following configuration in next.config.js, but it doesn’t work.

// next.config.js
module.exports = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'assets.example.com',
        port: '',
        pathname: '/**',
      },
    ],
  },
}

Next version is 12.3.1. What should I do to get the image correctly?

2

Answers


  1. Chosen as BEST ANSWER

    It has been solved, because I set the domains of images to [] in the code behind


  2. You don’t need remotePatterns if you just plan to use every path of a domain.

    Instead, you can use domains:

    // next.config.js
    module.exports = {
        images: {
            domains: ["assets.example.com"]
        }
    }
    

    Also, the fact that your snippet is not working seems to me as you had modified your next.config.js file but haven’t restarted the server, if not, after every change to the config file you must stop the server and restart it with npm run dev to see the changes

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search