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 file load incorrect #10440

Closed
7 tasks done
iivu opened this issue Oct 12, 2022 · 5 comments · Fixed by #10798
Closed
7 tasks done

env file load incorrect #10440

iivu opened this issue Oct 12, 2022 · 5 comments · Fixed by #10798
Labels
documentation Improvements or additions to documentation

Comments

@iivu
Copy link

iivu commented Oct 12, 2022

Describe the bug

I have a .env file looks like this:

APP_SIGN_SALT="PICUE#3$LCDG56h$LBNOD3*1H6ER4Y#DN12G6Z3J"

But in my app, the env variable became this:

console.log(import.meta.env.APP_SIGN_SALT);  // =>PICUE#3*1H6ER4Y#DN12G6Z3J

In dotenv@16.0.3, the env variable is correct:

require('dotenv').config();
console.log(process.env.APP_SIGN_SALT); // => PICUE#3$LCDG56h$LBNOD3*1H6ER4Y#DN12G6Z3J

Reproduction

https://stackblitz.com/edit/vitejs-vite-j9ece2?file=src/App.vue

Steps to reproduce

No response

System Info

System:
    OS: macOS 12.3.1
    CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
    Memory: 779.70 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.22.15 - ~/.nvm/versions/node/v16.13.1/bin/yarn
    npm: 8.5.5 - ~/.nvm/versions/node/v16.13.1/bin/npm
  Browsers:
    Chrome: 106.0.5249.103
    Firefox Developer Edition: 106.0
    Safari: 15.4

Used Package Manager

pnpm

Logs

No response

Validations

@Dunqing
Copy link
Contributor

Dunqing commented Oct 12, 2022

It looks like a version issue, vite uses dotenv@14.3.2.

@Shinigami92
Copy link
Member

Looks like you are using $ in your value, but dotenv supports variables in values, so my guess it you need to e.g. escape the $

@iivu
Copy link
Author

iivu commented Oct 12, 2022

yeah, when i escape the $, the value is correct:

APP_SIGN_SALT="PICUE#3\$LCDG56h\$LBNOD3*1H6ER4Y#DN12G6Z3J"

But dotenv@16.0.3 doesn't have this issue, so i think should update dotenv version ?

Looks like you are using $ in your value, but dotenv supports variables in values, so my guess it you need to e.g. escape the $

@iivu iivu changed the title env file load fail env file load incorrect Oct 12, 2022
@sapphi-red
Copy link
Member

Vite uses dotenv-expand so I think this is an expected behavior.
https://github.com/motdotla/dotenv-expand#what-rules-does-the-expansion-engine-follow

I think we should add some explanation about this here.
https://vitejs.dev/guide/env-and-mode.html#env-files

I guess you thought it work with dotenv@16.0.3 because you did not use dotenv-expand.

@sapphi-red sapphi-red added documentation Improvements or additions to documentation and removed pending triage labels Oct 14, 2022
@cjosue15
Copy link
Contributor

cjosue15 commented Nov 5, 2022

I would like to help with update in the documentation :), i'm gonna send my PR

cjosue15 added a commit to cjosue15/vite that referenced this issue Nov 5, 2022
@sapphi-red sapphi-red linked a pull request Nov 6, 2022 that will close this issue
8 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants