Environment variable not working?

Hey there,

it seems i can’t get this to work. Added API_BASE_URL to Environment section as well as to the PM2 env object.

It seems that the env variable is not working inside nuxt.config.js:

axios: {
baseURL: process.env.API_BASE_URL,
browserBaseURL: process.env.API_BASE_URL

Any idea what i am doing wrong? Am i taking the right approach here?

It works when building on my server so it seems that github ist not getting the env variables on building. Any idea on how to do that? With the workflow file being part of the repo i can’t commit such env variables into it for obvious reasons so what would the best approach be?

Thank you!

Good question!

If environment variables are required during build and you are using GitHub Actions, then it is true that we don’t have a way to send .env to GitHub. In this case, I’d recommend updating the workflow file and passing in the variables using GitHub Secrets so that there is security around them. Check out their docs for some direction on how to accomplish that - https://docs.github.com/en/actions/security-guides/encrypted-secrets

1 Like