env file load incorrect
See original GitHub issueDescribe 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
dotenv file is not loading environment variables - Stack Overflow
This fixed my problem with "undefined" .env variables. I even have another project running with the same exact setup for configuring server and...
Read more >5 reasons why your .env environment variables don't work
1. Your framework doesn't automatically load .env files. ... While some frameworks and packages come built-in support for environment variables ...
Read more >Laravel 5 loading wrong .env file - Laracasts
I figured it loads the wrong . env file because when i dump the env database: var_dump(env('DB_DATABSE')); It some times return the name...
Read more >Serverless Dotenv Plugin
Preload function environment variables into Serverless. Use this plugin if you have variables stored in a .env file that you want loaded into...
Read more >Allow environment variables to load from .env file : PY-5543
I'm currently trying to use Heroku and Django. Heroku requires that all local settings are loaded through environment variables. To match this, I...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I would like to help with update in the documentation 😃, i’m gonna send my PR
Vite uses
dotenv-expand
so I think this is an expected behavior. https://github.com/motdotla/dotenv-expand#what-rules-does-the-expansion-engine-followI 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 usedotenv-expand
.