You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next 14中images.domains弃用警告及配置冲突问题求助

解决Next.js 14中Images配置的弃用警告与域名验证错误问题

你的问题核心在于remotePatterns的配置不符合Next.js规则:hostname: "**"这种全局通配符写法不被系统识别,导致移除domains后无法通过res.cloudinary.com的域名合法性校验。

正确配置方案

完全移除domains配置项,同时修正remotePatterns的规则,针对res.cloudinary.com设置明确的远程访问模式:

/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: "https",
        hostname: "res.cloudinary.com",
        // 如需匹配该域名下所有路径,可添加以下配置(可选)
        // pathname: "/**",
      },
    ],
  },
};

module.exports = nextConfig;

关键说明

  • Next.js的remotePatterns不支持用**作为完整hostname来放行所有域名,必须指定具体主机名(或带前缀的通配符,比如*.res.cloudinary.com用于匹配所有子域名)。
  • 若需允许多个域名,可在remotePatterns数组中添加多个配置对象,每个对象对应一个域名的规则。
  • 修改配置后需重启Next.js开发服务器,确保新配置生效。

内容的提问来源于stack exchange,提问作者vishwajeet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 16:04:50