Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
7 tasks done
nezed opened this issue Mar 15, 2024 · 5 comments
Open
7 tasks done

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

nezed opened this issue Mar 15, 2024 · 5 comments
Labels
bug: upstream Bug in a dependency of Vite p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@nezed
Copy link

nezed commented Mar 15, 2024

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

  • have any setup with Vite@5.1.2+
  • have any .env file setup
  • in .env file have an env variable vith env expansion and trailing content

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

Copy link

stackblitz bot commented Mar 15, 2024

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

@nezed
Copy link
Author

nezed commented Mar 15, 2024

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

@nezed nezed changed the title Env expansion is broken in vite@5.1.2 - 5.1.6 Breaking change to env vars expansion since vite@5.1.2 Mar 15, 2024
@sapphi-red sapphi-red added bug: upstream Bug in a dependency of Vite p3-minor-bug An edge case that only affects very specific usage (priority) labels Mar 16, 2024
@akashMasih
Copy link

Working on this issue

@bitbirddev
Copy link

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

@nezed
Copy link
Author

nezed commented Jun 3, 2024

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 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: upstream Bug in a dependency of Vite p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

4 participants