Vue-cli: custom ENV variables are undefined all the time

Created on 18 Jun 2018  路  7Comments  路  Source: vuejs/vue-cli

Version

3.0.0-beta.15

Reproduction link

https://github.com/VladPavliuk/Client-games

Steps to reproduce

  1. Clone repository mentioned before.
  2. npm run serve.
  3. Look in the console of browser.

What is expected?

I expect to use some variable wich defined in env files and see it value

What is actually happening?

Instead, I see undefined every time when I try to usesome custom env variable

Most helpful comment

I was having the same issue but the issue I was having was that I did not rebuild the project by stopping the development environment and re-running 'npm run serve'.
After an hour of frustration I figured it out. I was having a bad morning. The same may be happening to others who are expecting that the environment variables will be available after a hot-reload instead of re-building.

All 7 comments

As the doc says, only env vars starting with VUE_APP will be exposed to your client code.

I was having the same issue but the issue I was having was that I did not rebuild the project by stopping the development environment and re-running 'npm run serve'.
After an hour of frustration I figured it out. I was having a bad morning. The same may be happening to others who are expecting that the environment variables will be available after a hot-reload instead of re-building.

I was having the same issue but the issue I was having was that I did not rebuild the project by stopping the development environment and re-running 'npm run serve'.

For me it took a cople of restarts for this to apply. Even emptied the browser cache. Is there some expiration time? Very annoying feature.

I fixed it by running
npm run build
npm run dev
then it started reading the env values.

I found this issue too. I fixed by restart my notebook and re-run project again.

I was having the same issue but the issue I was having was that I did not rebuild the project by stopping the development environment and re-running 'npm run serve'.
After an hour of frustration I figured it out. I was having a bad morning. The same may be happening to others who are expecting that the environment variables will be available after a hot-reload instead of re-building.

This was my issue. Thank you.

variables should start with VUE_APP_*

Was this page helpful?
0 / 5 - 0 ratings