Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs Next.js在本地目录中搜索图像,而不是在AWS上_Reactjs_Amazon Web Services_Next.js_Nextjs Image - Fatal编程技术网

Reactjs Next.js在本地目录中搜索图像,而不是在AWS上

Reactjs Next.js在本地目录中搜索图像,而不是在AWS上,reactjs,amazon-web-services,next.js,nextjs-image,Reactjs,Amazon Web Services,Next.js,Nextjs Image,我们正在将我们的应用程序从Create React应用程序转换为Next.js Next.js应该从AWS加载图像,但这不会发生。为什么? 几天前它起作用了。你认为是缓存问题还是什么 你有什么想法吗 在Next.js中,应用程序从本地URL加载图像: http://localhost:3000/_next/image?url=https%3A%2F%2Fticket-t01.s3.eu-central-1.amazonaws.com%2Fob8h_0.cover.jpg&w=1200&q=100

我们正在将我们的应用程序从Create React应用程序转换为Next.js

Next.js应该从AWS加载图像,但这不会发生。为什么?

几天前它起作用了。你认为是缓存问题还是什么

你有什么想法吗

在Next.js中,应用程序从本地URL加载图像:

http://localhost:3000/_next/image?url=https%3A%2F%2Fticket-t01.s3.eu-central-1.amazonaws.com%2Fob8h_0.cover.jpg&w=1200&q=100

next.config.js

const{nextI18NextRewrites}=require(“next-i18next/rewrites”);
常量localesubpath={
胡:"胡",,
恩:“恩”
};
module.exports={
重写:async()=>nextI18NextRewrites(localesubpath),
publicRuntimeConfig:{
本地子路径
},
图像:{
域名:[“ticket-t01.s3.eu-central-1.amazonaws.com”]
}
};
1图像标签:

在React中,AWS或图像加载没有问题

编辑

尝试访问映像时的console.log:


我设法解决了这个问题:

更改:

module.exports = {
  rewrites: async () => nextI18NextRewrites(localeSubpaths),
  publicRuntimeConfig: {
    localeSubpaths
  },
  images: {
    domains: ["ticket-t01.s3.eu-central-1.amazonaws.com"]
  }
};
致:

按如下方式更改图像组件:

<Image
  src={`${props.imgId}_0.cover.jpg`}
  className={styles.imageEventMain}
  alt="main event"
  layout="responsive"
  width={1795}
  height={1000}
  quality={100}
/>;

这应该能奏效

当图像试图加载到你的应用程序时,你有没有遇到任何错误?你能从浏览器直接访问图像吗?我上传了一张控制台的图片到问题中。我在同一个Url上访问CreateReact应用程序中的这些图像,我必须将这些图像转换为Next.js。我认为主要的问题是Next想从localhost加载图像,但它们在AWS上。图像是从localhost提供的,因为您使用的是
Next/image
Next.js将使用其内置的图像优化来优化图像并为其提供服务。没关系,我现在明白了,但是在这种情况下,为什么图像在localhost上不可用,在next.js缓存它们的路径上?@GyarmatiIstván你最终解决了这个问题吗?面对同样的问题
<Image
  src={`${props.imgId}_0.cover.jpg`}
  className={styles.imageEventMain}
  alt="main event"
  layout="responsive"
  width={1795}
  height={1000}
  quality={100}
/>;