当你在 Next.js 中使用 next/image
组件时,为了确保安全性,需要在 next.config.js
文件里配置允许使用的图片域名。你遇到的这个错误提示表明,https://via.placeholder.com/50
这个图片源的域名 via.placeholder.com
没有在 next.config.js
文件的 images
配置项中进行配置。
Error: Invalid src prop (https://via.placeholder.com/50) on `next/image`, hostname "via.placeholder.com" is not configured under images in your `next.config.js` See more info: `next/image` Un-configured Host | Next.js
在next.config.js中配置如果没有该文件直接创建即可 :
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
/* config options here */
reactStrictMode: true,
images: {
domains: ['via.placeholder.com'],
},
};
export default nextConfig;