-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Regression in .env variable expansion when loading additional files #18975
Comments
I assume it's coming from the breaking change of dotenv-expand #18697, but this seems like something unintended. |
Oh, this looks tricky. Since the first I'm not sure what we can do about this though. Workaround is to add empty Also here is the repro with only dotenv-expand https://stackblitz.com/edit/github-prsj2pg4?file=repro.mjs import { expand } from 'dotenv-expand';
const env1 = {
SECOND: 'foo',
};
const env2 = {
FIRST: 'ok',
SECOND: 'expand-first-${FIRST}',
};
const env2Expanded = expand({ parsed: { ...env2 }, processEnv: {} }).parsed;
const merged = Object.fromEntries([
...Object.entries(env1),
...Object.entries(env2),
]);
const mergedAndExpanded = expand({
parsed: { ...merged },
processEnv: {},
}).parsed;
console.log({
env1,
env2,
env2Expanded,
merged,
mergedAndExpanded,
}); {
env1: { SECOND: 'foo' },
env2: { FIRST: 'ok', SECOND: 'expand-first-${FIRST}' },
env2Expanded: { FIRST: 'ok', SECOND: 'expand-first-ok' },
merged: { SECOND: 'expand-first-${FIRST}', FIRST: 'ok' },
mergedAndExpanded: { SECOND: 'expand-first-', FIRST: 'ok' }
} |
Describe the bug
There seems to be a regression in Vite 6 related to loading extra .env files (.env.local or .env.production) related to parameter expansion.
In the extra loaded .env files where in the normal .env file the same variable is defined the expansion does not work.
Given:
The VITE_SOURCE variable does not get expanded into VITE_EXPANDED
Result:
Expected:
If i specify a variable with the same name in the .env file it does get expanded correctly.
Reproduction
https://stackblitz.com/~/github.com/tionkje/vitejs-vite-hp7equ9q
Steps to reproduce
Run
npm install
followed bynpm run dev
System Info
System: OS: Linux 5.0 undefined CPU: (7) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 18.20.3 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 10.2.3 - /usr/local/bin/npm pnpm: 8.15.6 - /usr/local/bin/pnpm npmPackages: vite: ^6.0.3 => 6.0.3
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: