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

Environment variables order affects the build hashes #11187

Closed
7 tasks done
mcchrish opened this issue Dec 5, 2022 · 1 comment
Closed
7 tasks done

Environment variables order affects the build hashes #11187

mcchrish opened this issue Dec 5, 2022 · 1 comment

Comments

@mcchrish
Copy link

mcchrish commented Dec 5, 2022

Describe the bug

When defining environment variables depending on the order would result in a different build, and hence different hashes. Example:


.env contains:

VITE_1=1
VITE_2=2

vite build results:

> env-test@0.0.0 build
> vite build

vite v3.2.4 building for production...
✓ 3 modules transformed.
dist/index.html                 0.38 KiB
dist/assets/index.06d1098a.js   0.82 KiB / gzip: 0.47 KiB

.env contains:

VITE_2=2
VITE_1=1

vite build results:

> env-test@0.0.0 build
> vite build

vite v3.2.4 building for production...
✓ 3 modules transformed.
dist/index.html                 0.38 KiB
dist/assets/index.753dce18.js   0.82 KiB / gzip: 0.47 KiB

Specifically the env variable replacements have changed console.log({VITE_2:"2",VITE_1:"1",BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0}.VITE_3)

Reproduction

https://github.com/mcchrish/vite-env-test

Steps to reproduce

  1. Define .env with content describe above.
  2. Run npm run build, notice the file hashes.
  3. Define .env with a different order of env as describe above.
  4. Run npm run build, and compare the file hashes from the previous build

System Info

System:
    OS: macOS 13.0.1
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 60.16 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.18.0 - /usr/local/bin/node
    Yarn: 1.22.18 - ~/Library/Application Support/npm/bin/yarn
    npm: 8.19.2 - /usr/local/bin/npm
  Browsers:
    Chrome: 107.0.5304.121
    Firefox: 107.0.1
    Safari: 16.1
  npmPackages:
    vite: ^3.2.3 => 3.2.4

Used Package Manager

npm

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Dec 5, 2022

Duplicate of #8663. The fix is in v4 but will be backported to v3 in #11189

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants