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

Env vars will not be inserted into assets if the asset is prefixed with an extra slash on request #17341

Open
7 tasks done
rschristian opened this issue May 29, 2024 · 0 comments · May be fixed by #19059
Open
7 tasks done
Labels
feat: dev dev server p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@rschristian
Copy link
Contributor

Describe the bug

Somewhat related to #17340

While /main.js & //main.js refer to the same asset, and will result in the same asset "source" being served, the latter will be missing any handling of env vars.

While yes, this was a typo, it feels weird that it's not being handled correctly. I'd expect the asset to not resolve or be handled the same in both cases.

Reproduction

https://github.com/rschristian/bug__vite-env-vars

Steps to reproduce

  1. npm install && npm run dev
  2. navigate to http://localhost:5173 -- to workaround Dev server is stateful in regards to env vars #17340
  3. navigate to http://localhost:5173/main.js
  4. Notice the returned asset looks like this:

/main.js

import.meta.env = {"BASE_URL": "/", "MODE": "development", "DEV": true, "PROD": false, "SSR": false};console.log(`vite mode: ${import.meta.env.MODE}`);

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1haW4uanMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0Lm1ldGEuZW52ID0ge1wiQkFTRV9VUkxcIjogXCIvXCIsIFwiTU9ERVwiOiBcImRldmVsb3BtZW50XCIsIFwiREVWXCI6IHRydWUsIFwiUFJPRFwiOiBmYWxzZSwgXCJTU1JcIjogZmFsc2V9O2NvbnNvbGUubG9nKGB2aXRlIG1vZGU6ICR7aW1wb3J0Lm1ldGEuZW52Lk1PREV9YCk7XG4iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsTUFBTSxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQyxXQUFXLENBQUMsQ0FBQyxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLEtBQUssQ0FBQyxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQzsifQ==
  1. navigate back to http://localhost:5173//main.js
  2. Notice the return asset looks like this:

/main.js

console.log(`vite mode: ${import.meta.env.MODE}`);

System Info

System:
    OS: Linux 6.8 EndeavourOS
    CPU: (4) x64 AMD Ryzen 7 5800X 8-Core Processor
    Memory: 6.44 GB / 11.65 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 18.20.2 - /usr/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.7.0 - /usr/bin/npm
    pnpm: 9.1.2 - /usr/bin/pnpm
  Browsers:
    firefox-developer-edition: 127.0b4
  npmPackages:
    vite: ^5.2.0 => 5.2.12

Used Package Manager

npm

Logs

No response

Validations

@rschristian rschristian changed the title Env vars will not be inserted into assets if they're prefixed with an extra slash Env vars will not be inserted into assets if the asset is prefixed with an extra slash on request May 31, 2024
@sapphi-red sapphi-red added p2-edge-case Bug, but has workaround or limited in scope (priority) feat: dev dev server labels Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: dev dev server p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants