-
Hi guys , I already created and described my problem on StackOverflow and no one is answering yet , pls check https://stackoverflow.com/questions/72886839/next-js-image-from-public-folder-not-loading-on-dynamic-paths |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 19 replies
-
Hi, A few things:
<img src="/image-name.png" alt="..." /> Next.js knows that static assets are in the public file, so you can skip saying
Now into the issue, do you have a middleware file? What Nextjs version are you using? I tried with 12.2.0, and it works fine. Do you have a reproduction repo? |
Beta Was this translation helpful? Give feedback.
-
Sorry for the wait. so i recreated it here and it worked somehow idk why https://stackblitz.com/edit/nextjs-cavc5g?file=pages%2F_app.js,components%2FNavbar.js,pages%2Fsomething%2Fsomething1%2F[id].js,pages%2Findex.js,package.json |
Beta Was this translation helpful? Give feedback.
-
Hi The issue is the /** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
images: {
loader: "akamai",
path: "", // <----- THIS IS THE ISSUE
},
};
module.exports = nextConfig; You should have the path set to /** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
images: {
loader: "akamai",
path: "/",
},
};
module.exports = nextConfig; Why does it happen only on dynamic routes? Well it doesn't just happen in dynamic routes. It happens because of the path depth. If you create The above is key because, when the Using the Details of implementationIf you must know why: The akamai loader looks like: function normalizeSrc(src: string): string {
return src[0] === '/' ? src.slice(1) : src
}
function akamaiLoader({
config,
src,
width,
}: ImageLoaderPropsWithConfig): string {
return `${config.path}${normalizeSrc(src)}?imwidth=${width}`
} When the BonusThere's this piece of JSX in the NavBar: <Link href="/abiplatform">
<Image src={SquareLogo} alt="brandergate square logo" />
</Link> Wrap the image with an anchor tag. |
Beta Was this translation helpful? Give feedback.
-
When I set |
Beta Was this translation helpful? Give feedback.
-
I’m forgot how to fix it, but I give up use path.

… Muhammad Zourdy ***@***.***> 於 2022年11月22日 上午11:11 寫道:
@icyJoseph <https://github.com/icyJoseph> I kinda have the same issue, and you mentioned in the above statement that the middleware might also cause it? Could you please explain to me what is the best way to fix it?
—
Reply to this email directly, view it on GitHub <#38382 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALXWZZ7QD45JPP7DOA64B73WJQ2X3ANCNFSM522NWNUQ>.
You are receiving this because you commented.
|
Beta Was this translation helpful? Give feedback.
-
Next.js can serve static files, like images, under a folder called public in the root directory. Files inside public can then be referenced by your code starting from the base URL (/). For example, if you add me.png inside public, the following code will access the image: `import Image from 'next/image' |
Beta Was this translation helpful? Give feedback.
-
Next app router has a serious problem in production when you try to access the image from the public folder from the url, it just fall to 404. I tried to report it but they close the issue. Try it! |
Beta Was this translation helpful? Give feedback.
-
No that’s not what I mean. Using next is canary latest release and Vercel I wasn’t able to access images from the browser, in development my images were correctly shown, but in production a 404 appears when I tried to access the images from browser. I didn’t make much debugging because I was in production and so I had to switch to cloudinary.
However on my side I didn’t make a lot of stuff that could have broken the public dir, so if you can take a look at it and tell me if was my issue or if there is an issue related.
Or maybe vercel?
Because in development everything works fine!
If you don’t understand what I mean, I can access the images using the next image component, but then it happens that I use an image as og_image and when I went to check if it was correctly displaying on the browser, it wasn’t instead there was a 404 error with some strange messages, I also had open an issue but was closed as it was without repro.
Sorry I’m not English, I hope you understand my issue.
Inviato da iPhone
On Aug 22, 2024, at 6:24 PM, jean1190 ***@***.***> wrote:
It's as intended unfortunately. It's static and not dynamic.
—
Reply to this email directly, view it on GitHub<#38382 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AWIQD3LYCM3CYYSD47T5NLTZSYGEVAVCNFSM522NWNU2U5DIOJSWCZC7NNSXTOSENFZWG5LTONUW63SDN5WW2ZLOOQ5TCMBUGIYTKNRR>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I didn’t change it in production
Inviato da iPhone
On Aug 22, 2024, at 6:43 PM, jean1190 ***@***.***> wrote:
I had the exact same problem. The thing is, the "public" path cannot reload new files in prod even if it works in dev.
—
Reply to this email directly, view it on GitHub<#38382 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AWIQD3PMNMYQKHIUWB3YJ6DZSYIMXAVCNFSM522NWNU2U5DIOJSWCZC7NNSXTOSENFZWG5LTONUW63SDN5WW2ZLOOQ5TCMBUGIYTONZZ>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
any update for this problem ? in nextJS 15 its same too i tried config next.config.ts but nothing happened here of my last config import type { NextConfig } from "next";
|
Beta Was this translation helpful? Give feedback.
Hi
The issue is the
path
used for images in the Next.js config file.You should have the path set to
/
Why does it happen only on dynamic routes? Well it doesn't just happen in dynamic routes. It happens because of the path depth.
If you create
pages/register/foo.js
, the same issue happens.The above is key because, when…