Next.js Discord

Discord Forum

Next.JS app deploy in sub folder

Answered
White-winged Scoter posted this in #help-forum
Open in Discord
White-winged ScoterOP
I want to deploy my Next.js project to https://xyz.com/my-app, but my assets and <Link> tags are not functioning correctly. How can I resolve this issue?
Answered by averydelusionalperson
IDK how you are deploying it, but u can use basePath ig.

https://nextjs.org/docs/app/api-reference/next-config-js/basePath
View full answer

18 Replies

IDK how you are deploying it, but u can use basePath ig.

https://nextjs.org/docs/app/api-reference/next-config-js/basePath
Answer
@averydelusionalperson IDK how you are deploying it, but u can use `basePath` ig. https://nextjs.org/docs/app/api-reference/next-config-js/basePath
White-winged ScoterOP
Actually <Link> tag working fine. But <Image> not working.
For example
Not working code
<Image src="/images/logo.png" width="50px" height="50px" alt="logo" />

Working code
<Image src="/my-app/images/logo.png" width="50px" height="50px" alt="logo" />

I have already added basePath in the next.config file, but the <Image> tag does not automatically append the path before the relative URL. Therefore, I am forced to manually add basePath before the relative URL.
@joulev If you import the image statically, does it work?
White-winged ScoterOP
Understood.
But what about metadata manifest file?
it's also not working
@White-winged Scoter But what about metadata manifest file?
Same reason. Instead of this, add app/manifest.json instead
Basically you probably should refrain from using the public folder wherever possible due to this basePath thingy
Some things might automatically get the base path, some don’t
So things that don’t depend on the path, such as statically imported images and file-based metadata, are immune to this problem
its a string
@White-winged Scoter "file-based metadata" means?
Meaning instead of adding manifest.json to public and reference it in a metadata export, you add the manifest.json file in app/. https://nextjs.org/docs/app/api-reference/file-conventions/metadata
White-winged ScoterOP
@joulev thanks for your answer. I think it's working fine now.
Thank you for your help 👍