VUE/CLI .env variables returns undefined - vue.js

I'm using #vue/cli 4.2.3 but when I create a .env file in my project root folder and declared a new env variable in it then print it in any component it returns undefined.
My env variable is like
VUE_APP_NAME=VALUE
and I'm calling it like
console.log(process.env.VUE_APP_NAME)
and the result is always undefined
Any help, pls?

With the information you give it seems that you are doing well.
The file is in the root.
The variable starts by VUE_APP_
I would check that the .env file has no extension.

Related

How to specify another directory or name for the .env file in Nuxt

I don't want to follow the convention of putting my environment variable (.env file) at the root directory of my Nuxt project.
How can I achieve another directory or even name for it without using the #nuxtjs/dotenv module? (I know this one is already baked into Nuxt since v2.13 and hence, not needed anymore).
Looking at this answer: https://github.com/nuxt/nuxt.js/issues/8331#issuecomment-727533175
You can specify a different location and name if you'd like, with the following
yarn dev --dotenv variables/.env_file
With the following structure
Of course, this will work with yarn generate and yarn build.
I got no luck with the --dotenv flag, so I'm just using replacing .env with the desired contents upon build or serve, like cp .env.xxx .env && yarn dev.
Not the prettiest, but good enough.
In your case the command would be cp variables/.env_file .env && yarn dev.

Nuxt command line pass arguments

I want to pass some arguments to nuxt command line like:
nuxt --myvar a
How to read this myvar inside nuxt.config.js?
I need this because I have 3 .env (localhost, production and development) files, but with current NODE_ENV I can use only 2 (production and development).
You should check out the https://github.com/nuxt-community/dotenv-module.
The module loads variables from your .env file directly into your
nuxt.js application context and process.env.

Vue.js: To Get Environment Variables in js File

I have created .env file to set environment variables as shown below:
Inside which I have given below mentioned code.
VUE_APP_BASEURL="https://qa-apps-nodejs.Dtech.com:9000/"
PORT=8080
I have written below code in my js file and executed npm install dotenv:
require('dotenv').config();
console.log(process.env.VUE_APP_BASEURL);
With the above code, I need to get https://qa-apps-nodejs.Dtech.com:9000/ in console. But instead I'm getting:
undefined
Just restart your server as newly created env variables are not available only after hot-reload you have to rebuild your application (restart your server). For reference you can look here
No need to install "dotenv" simply place .env file in the root of your project (at the same level of your package.json file) and Vue CLI will handle the reset. Side note; as of Vue CLI 3 only variables that start with VUE_APP_ will be loaded. make sure also to rerun npm run serve again to restart your server.
for more details: visit docs

Can't set env variables in my vuejs2 project

I'm trying to set my API URL in a .env file, my .env file is in the root folder of my project. I'm using VUE_APP_ prefix.
According to the doc .env file is loaded in any case. So should'nt I be able to get it everytime?
I m using MacOS, no Vuex.
My .env file
VUE_APP_API_URL: '"http://localhost:3000/"'
My .vue file
data() {
return {
test: process.env.VUE_APP_API_URL
}
},
I expected to get http://localhost:3000/ but I get undefined
Your syntax is wrong in your .env file. It's VUE_APP_API_URL = with = not :.
And you don't need double and simple quotes.
It should work this way:
VUE_APP_API_URL = 'http://localhost:3000/'
You'll need to reference the .env file in Webpack so that the variables get compiled into the build. The reason why you can't reference the variables is that they're not parsed into your build/public folder.
I'd use something like
https://github.com/mrsteele/dotenv-webpack

Component Pascal setup environment

I am trying to set up an environment for Component Pascal.
I chose the JVM option. I set a new system variable JROOT and added to the Path variable.
I try to run a new file I created via command line and got this error:
Error: Could not find or load main class CP.gpcp.gpcp
You must set a CPROOT environment variable to the instalation path of GPCP, something like
CPROOT=$HOME/gpcp;export CPROOT;
then add the bin directory to the GPCP executables to the PATH,
PATH=$CPROOT/bin:$PATH;export PATH;
both, in your .bashrc
Compile your CP program with
cprun gpcp <program>.cp
and execute with
cprun <program>