question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

env file load incorrect

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cjosue15commented, Nov 5, 2022

I would like to help with update in the documentation 😃, i’m gonna send my PR

1reaction
sapphi-redcommented, Oct 14, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found