-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
vue-cli-service serve does not set process.env.NODE_ENV, or any environmental variables. "process is not defined". #1128
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No 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? No Sign in to your account
Comments
From the documentation that you linked to:
Your .env file is in |
...thanks. It's finally working this morning though, so I'm happy. |
Getting similar issue. I have a .env in the root directory. When trying to console.log from a component ( console.log(process.env.VUE_APP_TEST), i get an undefined (even though it exists in the .env file). When console logging process.env , it does actually give me the BASE_URL and NODE_ENV, but those are values that are probably set as defaults somewhere. I have no way to change them or get it to pick up the .env file variables. |
This issue is closed. Either ask for help on forum.vuejs.org or open a new issue. |
For anyone else finding this, if you're using |
@RichPC I did... I still get |
Same problem as well.... I tried starting from scratch using Vue Cli3 to create a new project and also tried using the vue webpack template. None of them works! |
If someone stumbles in this as I did, it's not the solution is to use the terminal, run
|
I always create my .env files from within vscode, so the problem must be related to your system in some way. |
@mouafa thx, helped in my case |
I fixed it by running |
I have the same problem too! Were you able to solve it? |
For me helps not to place process.env.VUE_APP_* directly, but |
I have the problem in my index.html, where I wanted to set the title via env variable
This does not happen when building my docker image with this Dockerfile from https://vuejs.org/v2/cookbook/dockerize-vuejs-app.html I´ve just added @vue/cli-service-global because it could not finde the vue-cli-service out of the box
|
guys. i tried all your ways. touch .env, build and serve again. |
i set .env,but process is undefined . why? |
oh ,that's true. why? |
I tried following and it's not working for me.
Console Result: undefined |
Same steps like @hello2parth done and same issue. Also if you run with docker-compose and define there |
I'm having a similar problem, some var into before: |
Adding |
This is definitely a must add to the manual. The manual now does not make it clear that these values cannot be used in templates, only in javascript objects. Thank you for figuring this out and sharing it! |
I'm having a similar problem. Any methods to fix it? |
I think i have understood it. Firstly you can use Vue.prototype.process = Object.freeze({
env: process.env,
}) |
hi everybody, i was struggling for an hour to solve the same problem. i tried every changing mentioned above than i noticed that i'm using " : " instead of " = " |
TOP that's work for me |
Version
2.9.3
Reproduction link
https://github.com/DonHartman/vue-bug
Steps to reproduce
Clone the linked repo. (or Create a .env file for a new vue project in accordance with https://github.com/vuejs/vue-cli/blob/dev/docs/env.md, and give VUE_APP_TEST a value, then use it in code.)
Serve the project with "npm run serve" (I used powershell, if it makes a difference).
View the served app in a browser with dev tools open, I've included a "debugger;" line above the issue.
What is expected?
According to https://github.com/vuejs/vue-cli/blob/dev/docs/env.md , process.env.VUE_APP_TEST should have the "sample" value .
What is actually happening?
The code that accesses "process" throws the error "process is not defined".
The github repo linked has the fully initialized project (the first commit is auto-generated by vue-cli, the second is my minimal changes to recreate the issue). It can likely be reproduced with much less code, but I wanted to emphasize that it is a problem out-of-the-box with vue-cli, so I only made minimal changes to the pre-made project instead of a minimal project.
These are the settings I used to create it:
Run "vue create "
Choose manual settings
Typescript, Router, Vuex, Linkter / Formatter
yes, class style components
yes, babel polyfills
TSLint
Lint on save
In dedicated config files
The text was updated successfully, but these errors were encountered: