reactjs 主机名“storage.googleapis.com“未配置在images next js下

pn9klfpd  于 2022-12-12  发布在  React
关注(0)|答案(2)|浏览(111)

我收到以下消息:

Error: Invalid src prop (https://storage.googleapis.com/agrf-upload/abcd.png) on `next/image`, hostname "storage.googleapis.com" is not configured under images in your `next.config.js`
See more info: https://nextjs.org/docs/messages/next-image-unconfigured-host

但我的next.config.js如下所示:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  images: {
    domains: ['storage.googleapis.com', 'www.coinpayments.net', 'coinpayments.net'],
  },
  compiler: {
    removeConsole: false,
  },
  images: {
    minimumCacheTTL: 1500000,
  },
  swcMinify: true
}

module.exports = nextConfig

在我重新启动笔记本电脑之前,它一直工作得很好。我现在毫无头绪。请帮我整理一下。

t3psigkw

t3psigkw1#

我在配置中有另一个图像部分,它干扰了上面的图像块(用于指定域):

images: {
    minimumCacheTTL: 1500000,
  },

所以现在我更新的next.config.js看起来像这样:

const nextConfig = {
  reactStrictMode: true,
  images: {
    domains: ['storage.googleapis.com', 'coinpayments.net'],
    minimumCacheTTL: 1500000,
  },
  compiler: {
    removeConsole: false,
  },
  swcMinify: true
}

module.exports = nextConfig
wn9m85ua

wn9m85ua2#

推荐我:

// url: 'https://www.paypal.com/c2/webapps/mpp/home?locale.x=zh_C2" title="PayPal" onclick="javascript:window.open('https://www.paypal.com/c2/webapps/mpp/home?locale.x=zh_C2','WIPaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=1060, height=700'); return false;"><img src="https://www.paypalobjects.com/digitalassets/c/website/marketing/apac/C2/logos-buttons/optimize/Online_Primary_Acceptance_Mark_RGB_V2.jpg'

//next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  images: {
    remotePatterns: [{
      protocol: 'https',
      hostname: 'paypalobjects.com',
      port: '',
      pathname: '/digitalassets/c/website/marketing/apac/C2/logos-buttons/optimize/Online_Primary_Acceptance_Mark_RGB_V2.jpg'
    }]
  }
}

module.exports = nextConfig
  //xxx.tsx
  ...
  <Image
src = {
  "https://paypalobjects.com/digitalassets/c/website/marketing/apac/C2/logos-buttons/optimize/Online_Primary_Acceptance_Mark_RGB_V2.jpg"
}
alt = 'PayPal'
//fill
width = {200}
height = {127}
/>

相关问题