I've encountered an issue trying to use .env
variables in my Vue app. When I ran npm install process
, the only syntax that didn't result in an error when importing was:
import * as process from 'process';
Prior to this, I received the following error message:
Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
After running the suggested installation and adding "node" to types
in my tsconfig
file, I defined a member variable like so:
const testVar = process.env.TEST_VAR
I attempted both TEST_VAR=just test
and TEST_VAR="just test"
in my .env file. The .env file is located in the root folder of the project, outside the src
folder.
Despite all these efforts, the variable keeps returning as undefined.
mounted(){
console.log('ENV TEST -> ', this.testVar)
alert(`ENV2 : ${this.testVar}`)
...
}
If anyone could offer assistance with resolving this issue, it would be greatly appreciated. Thank you!