首页 > 解决方案 > 使用 NEXT/IMAGE 开玩笑时出错:`next/image` 上的 src 属性无效,主机名“res.cloudinary.com”未在`next.config.js` 中的图像下配置

问题描述

我用 img 做了一些测试,它非常好,但是当我添加下一个/图像时,会生成这个错误,即使配置了 next.config.js 文件,错误仍然存​​在。

Invalid src prop (https://res.cloudinary.com/dezwlfeyb/image/upload/v1635633843/Contabilidade-Smart-negativo-172_e5oyxn.png) on `next/image`, hostname "res.cloudinary.com" is not configured under images in your `next.config.js`
See more info: https://nextjs.org/docs/messages/next-image-unconfigured-host

  10 |   ui: ReactElement,
  11 |   { ...renderOptions }: CustomRenderProps = {}
> 12 | ) => render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>, renderOptions)

next.config.js

// eslint-disable-next-line @typescript-eslint/no-var-requires
const withPWA = require('next-pwa')
const isProd = process.env.NODE_ENV === 'production'

    module.exports = withPWA({
      pwa: {
        dest: 'public',
        disable: !isProd
      },
      images: {
        domains: ['localhost', 'res.cloudinary.com']
      }
    })

标签: jestjsnext.jsnextjs-image

解决方案


推荐阅读