简体   繁体   English

静态加载 NextJS 图像在生产环境中给出 404,但在本地主机上工作

[英]Statically loading NextJS Image gives 404 on production but works on localhost

I don't understand why the static image is not found on production, but works on localhost.我不明白为什么在生产环境中找不到 static 图像,但可以在本地主机上工作。 I put all my images in the directory: public/images/...我将所有图像放在目录中: public/images/...

/* image.tsx */
return (
<Image
  src={"/images/frame1.png"}
  width="1000"
  height="1000"
  alt="Control description"
  style={{
    height: "auto",
    maxWidth: "100%",
    userSelect: "none",
  }}
/>
)

/* next.config.js */

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
};

module.exports = nextConfig;

Cloudflare pages deployment: Cloudflare 页面部署: 在此处输入图像描述

Localhost:本地主机: 在此处输入图像描述

My file structure:我的文件结构: 在此处输入图像描述

first : did you try changing <Image/> to <img/> ?首先:您是否尝试将<Image/> to <img/> test this and see if it's fixed or not ( just to be sure where the problem is coming from )对此进行测试,看看它是否已修复(只是为了确定问题出在哪里)

second try this: change the name of the image files.from uppercase to lowercase letters.第二个尝试:将图像文件的名称从大写字母更改为小写字母。

That still a problem.那还是个问题。

I have the same situation, next/image ins't loading images in production from "public" folder.我有同样的情况,next/image 无法从“公共”文件夹中加载生产中的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM