1

I want my web app, that's built with Nuxt.js and Vue.js to access the environment variables that I added in the Netlify environment UI (setting menu).

When I run the local server I have no problem with my code accessing the .env file and retrieving the right codes.

But when I build it with Netlify, it returns undefined.

I have tried adding different prefixes to the env variables since I saw some people do this:

VUE_APP_MY_VARIABLE
NUXT_APP_MY_VARIABLE
VUE_MY_VARIABLE
NUXT_MY_VARIABLE

I do not understand why the variables can not be accessed when the site is live.

If you're missing any information, let me know and I will add it.

Thanks in advance!

2
  • you need to add the env variable into netlify from the menu they provided to add variable Commented Nov 24, 2020 at 18:25
  • That's what I meant with the UI / Setting menu. Does not work though Commented Nov 24, 2020 at 18:52

1 Answer 1

5

Maybe this page can help you! https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-env

Try:

NUXT_ENV_MY_VARIABLE 

instead of

NUXT_MY_VARIABLE

I use Netlify and Nuxt together with dotenv package:

"@nuxtjs/dotenv": "1.4.1",
Sign up to request clarification or add additional context in comments.

1 Comment

You, my good sir, are an absolute legend. I didn't really expect anyone to react anymore. But this completely solved it. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.