1

I created a .env file and put this inside of it:

VUE_APP_TEST='Hello'

Then in one of my components I tried console.log(process.env.VUE_APP_TEST), however, I get undefined in the console.

Not sure if this matters but to create the project I'm working for, I've used vue webpack-simple template.

I've seen a couple of articles and tutorials in which what I've already done works just fine, however, not so much in my case.

Onyx
  • 5,186
  • 8
  • 39
  • 86
  • 1
    `process.env` is a Nodejs object, it's not going to exist in the JavaScript environment running in the browser. – Paul May 25 '19 at 03:59
  • Hmmm, well the dude in this video https://youtu.be/nSmMkeNjjPg?t=1443 ( I've timestamped it to the exact moment where he uses the same object ) uses it and most of the articles I've found use it as well. The only difference is that I'm using vue-cli2 and not 3 so the configuration might be different or something. – Onyx May 25 '19 at 04:09
  • https://stackoverflow.com/questions/50828904/using-environment-variables-with-vue-js this may help – shashi verma May 25 '19 at 04:10
  • I assume you can't upgrade to 3, the changelog doesn't go back to before 3.* but you could try checking your node_modules to see if the package "dotenv" (https://www.npmjs.com/package/dotenv) was included. If it wasn't, install it. Try importing it, then calling it's config function from your main index.js file. Not sure if it will work, hence the comment. – Steve Hynding May 25 '19 at 04:43
  • Did you restart your application? Newly created .env will not be available through hot reload. – TommyF May 26 '19 at 12:56

0 Answers0