Skip to content

Exposed env vars are not available #6626

@jost-s

Description

@jost-s

Describe the bug

Using an .env file to define environment variables, static values are passed on and available in Vue as expected. Exposing existing env vars to Vue, however, does not work and produces empty values.

I've exposed the env var using the syntax from this comment.

STR:

  • open reproduction
  • start dev server with command PORT=4000 npm run dev

Expected:
PORT should be available from main.js and output 4000.

Actual:
PORT is an empty string.

Reproduction

https://stackblitz.com/edit/vitejs-vite-bxj6nd?devtoolsheight=33&file=.env

System Info

System:
    OS: macOS 11.6.1
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 1.36 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.2 - ~/.nix-profile/bin/node
    npm: 8.1.2 - ~/.nix-profile/bin/npm
  Browsers:
    Brave Browser: 97.1.34.81
    Safari: 15.2

Used Package Manager

npm

Logs

...
vite:config   env: {
vite:config     VITE_PORT: '',
vite:config     BASE_URL: '/',
vite:config     MODE: 'development',
vite:config     DEV: true,
vite:config     PROD: false
vite:config   },
...

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug: upstreamBug in a dependency of Vitep2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions