-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Not being able to read variables from .env #4403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not being able to read variables from .env #4403
Comments
Alternative options to use config/dev.env.js file and keep all the variables and values there... but I'm not sure if this is a good practice because these config files are tracked in the git repository. Should I add these file to .gitignore? Thanks. |
Thanks for submitting this issue! Due to our limited time, we ask you to include a reproduction link to a minimal full reproduction of your problem (for example in a GitHub repository) so we can find what is causing the issue. Thank you for your understanding! |
Hello! We get a lot of issues, so we currently close issues requiring feedback after 20 days of inactivity. It’s been at least 10 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. (A maintainer can also add the label Thanks for being a part of the Vue community! 💪💚️ |
Here is a basic reproduction of the issue: https://github.com/GiantZOC/vue-cli-environment-reproduction I created a new project with vue-cli, added a .env file and then tried to output the value in the console with main.js. |
@GiantZOC See https://cli.vuejs.org/guide/mode-and-env.html#environment-variables
|
Does that mean there's no way for us to access .env file during development? It would be annoying to keep building the bundle and testing |
What do you mean by "no way to access .env file"? You can access environment variables during development, they just need to start with |
The reasoning for this design: facebook/create-react-app#865 (comment) |
@pluus I just realized that the project you referenced in the original issue was not scaffolded by |
Thanks I will give it a shot! |
Version
3.9.3
Environment info
Steps to reproduce
In the root folder, I've created .env and added the following variable:
VUE_APP_SECRET=secret
In the main.js, i tried reading the variable by:
console.log(process.env.VUE_APP_SECRET) // I thought this would work but not.
console.log(process.env.SECRET) // tried this as well but still no luck.
before new Vue(.....) but all i'm getting are undefined. What am I missing?
What is expected?
displaying 'secret' in the console
What is actually happening?
Getting undefined
The text was updated successfully, but these errors were encountered: