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 basePath: `/${NEXT_PUBLIC_BASE_PATH)
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 www.example.com/docs it gives me 404, both on page and assets in the network.
Hey @SamO , thanks for the reply!
Looks like that based on https://netlify-file-browser.netlify.app/ 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
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:
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: www.example.com/docs/image.png is looking, wrongly, still in www.example.com/image.png.
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
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.