Skip to content

Not being able to read variables from .env #4403

Closed
@pluus

Description

@pluus

Version

3.9.3

Environment info

 System:
    OS: macOS 10.14.5
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
  Binaries:
    Node: 8.16.0 - /usr/local/opt/node@8/bin/node
    Yarn: Not Found
    npm: 6.4.1 - /usr/local/opt/node@8/bin/npm
  Browsers:
    Chrome: 76.0.3809.100
    Firefox: 68.0
    Safari: 12.1.1
  npmPackages:
    babel-helper-vue-jsx-merge-props: ^2.0.3 => 2.0.3
    babel-plugin-jsx-vue-functional:  2.1.0
    babel-plugin-transform-vue-jsx: ^3.5.0 => 3.7.0
    babel-preset-vue:  1.2.1
    babel-preset-vue-app:  1.3.2
    eslint-plugin-vue: ^4.0.0 => 4.7.1
    jest-serializer-vue: ^0.3.0 => 0.3.0
    vue: ^2.5.2 => 2.6.10
    vue-apexcharts: ^1.4.0 => 1.4.0
    vue-eslint-parser:  2.0.3
    vue-hot-reload-api:  2.3.3
    vue-jest: ^1.0.2 => 1.4.0
    vue-loader: ^13.3.0 => 13.7.3
    vue-router: ^3.0.1 => 3.0.7
    vue-style-loader: ^3.0.1 => 3.1.2
    vue-template-compiler: ^2.5.2 => 2.6.10
    vue-template-es2015-compiler:  1.9.1
  npmGlobalPackages:
    @vue/cli: 3.9.3

Steps to reproduce

In the root folder, I've created .env and added the following variable:

VUE_APP_SECRET=secret

In the main.js, i tried reading the variable by:

console.log(process.env.VUE_APP_SECRET) // I thought this would work but not.
console.log(process.env.SECRET) // tried this as well but still no luck.

before new Vue(.....) but all i'm getting are undefined. What am I missing?

What is expected?

displaying 'secret' in the console

What is actually happening?

Getting undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs reproductionThis issue is missing a minimal runnable reproduction, provided by the author

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions