Nextjs with basePath

Hello everyone!
I’m trying to deploy a nextjs (13.0.3) website that has the basePath option to essentially claim it has to be hosted on a subfolder.
I’ve set up and .env file with my variable and then
I’ve already prefixed the assets from public (as they claim it has to be manual) with
export const prefixAsset = (v) => `${process.env.NEXT_PUBLIC_BASE_PATH}/${v}

So far so good in local in dev mode and after I build and call npm run start but when I deploy here on Netlify when I go to the subpage, like it gives me 404, both on page and assets in the network.

Any clue?

Hi, did you tell netlify where to build your site from? Can you share what you put in your build settings. Also this doc might help:

Hey @SamO , thanks for the reply!
Looks like that based on website is deployed on root, so when on netlify it tries to access the right path of course it won’t find the assets.
ShouldI set something on netlify to explicit say to deploy on a subfolder?

I can provide you the right link but I’d like to keep it private in a DM due it’s a staging link and I can’t go public yet


hey there, just a ping to be sure you have seen my reply :slight_smile:

Sam’s been out the past couple of days. Certainly you can tell netlify to deploy only a subdirectory rather than the entire repo! That’s the “publish” directory shown in the deploy settings configuration. Here’s a sample screenshot from one of my sites:


You can edit that on the deploy settings page.

Hey @fool , thanks for the feedback!
And no, that is not working neither unfortunately.
Look like the issues come from the fact assets etc are deployed on root, so when it tries to find to access from the subfolder essentially is looking into the wrong path
For example: is looking, wrongly, still in
What I don’t understand that it’s working in dev mode, it’s working in local after npm run build and npm run start, so I assume it’s really something I’m doing wrong on netlify.

Wondering one thing, can it help if I send you over the link in DM? Can’t share since it’s a staging link :frowning:

Thanks in advanca!

Feel free to send a DM regarding the site link.

Thanks @hrishikesh , sent a DM with link and more info :slight_smile:

Sorry for the delay. Have you uploaded the .env file to your Git repo? If not, I believe you need to set the environment variable in your site settings, because as far as I can see, your site is getting deployed without the base path. I checked the latest deploy for the develop branch. The structure is as follows:


As you can see, no asset has got the prefix you’ve set in prefixAsset. However, if you visit index.html for your site, all your assets are being loaded over that path.

Try logging your environment variable in the build to see if it’s actually working.

Let me double check but looks like is loading it correctly


(I’ll DM you the entire log)