I am using a base path /base-path
for my Next app in next.config.js and using pages router, where ever environment variables are needed I am using process.env
to access it.
where ever public environment variables are used I am prefixing with NEXT_PUBLIC
to access it on the client, but it is not working on my development server when the application is deployed using ECS, while everything is working fine in my local, I checked the container envs, all the required variables are there but it’s like whenever the application is served the variables are undefined and base path which is loaded using NEXT_PUBLIC_APP_BASE_PATH
and is being used when I call any next api the base path is always undefined.
I have to specify this base path using NEXT_PUBLIC_APP_BASE_PATH
because images inside my public folder and api’s that are in pages/api folder do not pic basePath specified in next.config.js automatically, so whenever I call any api in the project and images are being used I have to prefix base path using this variable but since it is always undefined, nothing is working.
Initially I thought that everything was working fine on server side but not on client side but later I found out that server side code is also not picking this environment variable.
Shiv Shukla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.