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
It has been solved, because I set the domains of images to [] in the code behind
You don’t need
remotePatterns
if you just plan to use every path of a domain.Instead, you can use
domains
: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 withnpm run dev
to see the changes