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

Handle dynamic/destructured .dotenv variable access in main #57

Open
jrmdayn opened this issue Dec 2, 2021 · 4 comments
Open

Handle dynamic/destructured .dotenv variable access in main #57

jrmdayn opened this issue Dec 2, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@jrmdayn
Copy link

jrmdayn commented Dec 2, 2021

Hey 👋 ! Great work, thank you for this project!

I noticed that .env files are correctly read in dev mode in the main, but not in production (using yarn try for ex). Any idea on how I could make this work?

Thanks a lot 🙏

@karolis-sh
Copy link
Owner

Hi, how exactly are you using env variables in main? I have a feeling there might be an issue with env variable destructuring

@jrmdayn
Copy link
Author

jrmdayn commented Dec 4, 2021

In the main I look through process.env for variables.

I looked at the output of build --verbose and I do see the variables from my .env files being passed through the define prop to esbuild.

After further investigation, I realized that my logic for getting an env variable from the main was actually located under another folder shared/ where I call process.env etc.. If I log the content of process.env from a file within shared/ I do not see the variables coming from my dotenv files. But when I do this from a file in the main/ folder they are there...

I can work around this short term but it would be nice to understand what's going on..

@karolis-sh
Copy link
Owner

Yeah, if you don't use the variables directly, but rather dynamically or via destructuring it won't work (evanw/esbuild#438 (comment)). I might look later around for newer techniques to handle this better.

@jrmdayn
Copy link
Author

jrmdayn commented Dec 5, 2021

ok thanks for the pointers. That's a shame that esbuild does not handle this correctly out of the box 😢

@karolis-sh karolis-sh added the enhancement New feature or request label Jul 29, 2022
@karolis-sh karolis-sh changed the title Handle dotenv files in main Handle dynamic/destructured .dotenv variable access in main Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants