I am having a problem getting .env variables working in my Vue app. After npm install process this was the only syntax that didn't throw an error when trying to import.
import * as process from 'process';
Before this I also had the following error:
Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
I ran this install and added "node" to types in my tsconfig file.
I have a member variable defined like so,
const testVar = process.env.TEST_VAR
and have tried both TEST_VAR=just test and TEST_VAR="just test" inside my .env file.
The .env file itself is placed in the root folder of the project, ie. outside the src folder, but I have tried placing it inside the src folder also.
Despite all that, the var is coming back undefined.
mounted(){
console.log('ENV TEST -> ', this.testVar)
alert(`ENV2 : ${this.testVar}`)
...
}
I'd be very grateful for any help solving this. Thanks!
This module mostly exists to provide the nextTick functionality and little more. Maybe everything you needed wasdeclare const process?dotenvbut can't figure out how to use it in my component using Typescript.processis exposed by a bundler, which is unknown in your case. For Webpack/Vue CLIwebpack-envis used to provide respective TS types, can be used intypestsconfig section