最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Unable to use image files in the public folder of my Next.js project - Getting a 404 Error - Stack Overflow

programmeradmin0浏览0评论

I'm trying to use image files located in the public folder of my Next.js project, but I'm receiving a "404 Not Found" error in the browser. I have made sure that the relevant image files are in the correct path, the file names and extensions are correct, and my configurations are accurate. Specifically, I'm using the image file like this:

body{
  background-image: url(/public/frame.png);
}

I want to note that I have tested the same setup with regular HTML and CSS, and it works without any issues. However, when implementing it in my Next.js project, I encounter the "404 Not Found" error.

Here are my configurations:

Next.js version: 13.4.5

Do you have any suggestions or solutions? Why am I unable to use the image files in the public folder and getting a "404 Not Found" error?

Thank you in advance!

I expected the image located in the /public/images/frame.png path to be displayed as the background of the <body>

I'm trying to use image files located in the public folder of my Next.js project, but I'm receiving a "404 Not Found" error in the browser. I have made sure that the relevant image files are in the correct path, the file names and extensions are correct, and my configurations are accurate. Specifically, I'm using the image file like this:

body{
  background-image: url(/public/frame.png);
}

I want to note that I have tested the same setup with regular HTML and CSS, and it works without any issues. However, when implementing it in my Next.js project, I encounter the "404 Not Found" error.

Here are my configurations:

Next.js version: 13.4.5

Do you have any suggestions or solutions? Why am I unable to use the image files in the public folder and getting a "404 Not Found" error?

Thank you in advance!

I expected the image located in the /public/images/frame.png path to be displayed as the background of the <body>

Share Improve this question edited Jun 14, 2023 at 11:15 Librouse asked Jun 14, 2023 at 11:10 LibrouseLibrouse 471 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Remove the "public" from the path just write /frame.png

as mentioned in nextjs documentation https://nextjs/docs/app/building-your-application/optimizing/static-assets

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论