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
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.

Any clue?
Thanks!

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 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

Thanks!

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:

image

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: 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 :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:

/_next/static/m2ohijy8rvmn9bnzt1qe7/_ssgmanifest.js
/images/icons/arrow.svg
/images/icons/close.svg
/images/carousel-icon.svg
/_next/static/chunks/pages/_error-8e848193de3c139c.js
/images/icons/rotate.svg
/images/cards/icon-card-microplastic.svg
/models/air/pedestal.glb
/three/decoders/basis/readme.md
/three/decoders/draco/readme.md
/models/noise/hotspot.png
/models/melting/pyramid.glb
/models/melting/circle.glb
/models/melting/cube.glb
/images/cards/icon-card-noise.svg
/models/melting/doublecone.glb
/models/melting/permafrost.glb
/models/melting/blob.glb
/images/cards/icon-card-air.svg
/models/melting/platonic.glb
/images/icons/barcode.svg
/rive/air.riv
/images/cards/icon-card-melting.svg
/images/icons/hotspot-glow.png
/models/melting/cone.glb
/rive/noise.riv
/models/melting/cylinder.glb
/models/air/map.ktx2
/images/icons/hotspot.png
/axl/index.js
/audio/ui/stepnext.mp3
/audio/ui/stepprev.mp3
/models/melting/capsule.glb
/models/air/map.png
/images/google-logo.svg
/fonts/gothambook.woff2
/audio/ui/addclimatecost.mp3
/rive/microplastic.riv
/fonts/gothambook.woff
/fonts/gothammedium.woff2
/rive/melting.riv
/fonts/gothammedium.woff
/audio/ui/closecard.mp3
/models/microplastic/map.png
/audio/ui/carouselchange.mp3
/audio/ui/openhotspotmodal.mp3
/audio/air/air-step-enter-1.mp3
/images/icons/sidebar-cc.svg
/models/air/model.glb
/models/air/particles-paris.glb
/audio/air/air-step-enter-2.mp3
/audio/air/air-step-leave-1.mp3
/three/decoders/draco/draco_wasm_wrapper.js
/three/decoders/draco/gltf/draco_wasm_wrapper.js
/audio/air/air-step-leave-2.mp3
/audio/air/air-step-leave-3.mp3
/audio/air/air-step-enter-0.mp3
/audio/microplastic/digest.mp3
/audio/ui/opencard.mp3
/audio/air/air-step-leave-0.mp3
/three/decoders/basis/basis_transcoder.js
/audio/melting/melting-step-0.mp3
/audio/melting/melting-step-1.mp3
/models/air/particles-nyc.glb
/audio/air/air-step-enter-3.mp3
/models/noise/diffuse.ktx2
/audio/melting/melting-enter.mp3
/_next/static/chunks/polyfills-c67a75d1b6f99dc8.js
/models/noise/model.glb
/audio/microplastic/breath.mp3
/audio/noise/noise-step-2.mp3
/models/air/particles-nd.glb
/models/air/particles-sh.glb
/_next/static/chunks/framework-48286e0ad7f6b2fd.js
/audio/noise/noise-step-1.mp3
/three/decoders/draco/gltf/draco_decoder.wasm
/audio/melting/melting-step-bg-1.mp3
/three/decoders/draco/draco_decoder.wasm
/audio/noise/noise-step-0.mp3
/audio/air/air-step-bg-0.mp3
/audio/air/air-step-bg-2.mp3
/audio/melting/melting-step-bg-0.mp3
/three/decoders/basis/basis_transcoder.wasm
/three/decoders/draco/gltf/draco_decoder.js
/audio/microplastic/microplastic-step-1.mp3
/audio/air/air-step-bg-1.mp3
/audio/air/air-step-bg-3.mp3
/three/decoders/draco/draco_decoder.js
/audio/noise/noise-bg.mp3
/models/microplastic/stomach.glb
/models/microplastic/lungs.glb
/three/decoders/draco/draco_encoder.js
/audio/microplastic/microplastic-step-0.mp3
/three/decoders/draco/gltf/draco_encoder.js
/_next/static/m2ohijy8rvmn9bnzt1qe7/_buildmanifest.js
/images/icons/share.svg
/_next/static/chunks/pages/index-00ee63913bb9e8bb.js
/404.html
/_next/static/chunks/webpack-8bb1c850369c6711.js
/_next/static/css/d2420a7f26f33014.css
/index.html
/_next/static/chunks/main-c5525c9bc84147f5.js
/share.jpg
/_next/static/chunks/pages/_app-df0226db8ede848c.js

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

image

(I’ll DM you the entire log)