vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
66.09k stars 5.9k forks source link

Breaking change to env vars expansion since vite@5.1.2 #16175

Open nezed opened 3 months ago

nezed commented 3 months ago

Describe the bug

We're using env expansion feature for our .env files.

Given following .env file as example:

# .env
VITE_SOURCE=12345
VITE_EXPANDED=$VITE_SOURCE-678-ab

We expect, the behaviour of Vite@<=5.1.1:

console.log(import.meta.env.VITE_EXPANDED) // 12345-678-ab

Actual result for Vite@>=5.1.2:

console.log(import.meta.env.VITE_EXPANDED) // 12345

the -678-ab part is missing now

Reproduction

https://stackblitz.com/edit/vitejs-vite-yalk8f?file=.env

Steps to reproduce

UPD: Seems that the braking change have only affected the env expansion with kebab-cased content after the env var reference.

Example:

Vite@<=5.1.1 (correct)

image

Vite@>=5.1.2 (breaking change)

image

You can try it yourself by changing a Vite version in this minimalistic Vite-only example

System Info

Seems to be reproducible in setup and package manager.

Verified on:
Package managers: npm, pnpm
Envs: OS X, StackBlitz
Vite setup: `npm create vite` is just fine
.env loading method: both
 - .env in root directory with zero configuration
 - via `loadEnv()`

Used Package Manager

npm

Logs

No response

Validations

stackblitz[bot] commented 3 months ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

nezed commented 3 months ago

The root cause seems to be dotenv-expand@^11.0.3, brought to Vite@5.1.2 with #15875

See the issue motdotla/dotenv-expand#124

akashMasih commented 1 month ago

Working on this issue

bitbirddev commented 1 month ago

having the same issue. thanks @akashMasih for working on a solution!

nezed commented 1 month ago

Hey @akashMasih @bitbirddev, don't hesitate to collaborate on root-cause issue motdotla/dotenv-expand#124 as well. Just a thumbs up or a comment would be great :wink: