Open seniorquico opened 3 months ago
Hey @seniorquico thanks for the issue. It seems we need to conditionally follow Vite's env parsing logic for vite projects.
We are open to contributions for this one! Feel free to submit a PR, we'd be more than happy to get it released with the next release.
Hey @seniorquico we've discussed with the team and thinking that parsing dotenv files in CLI may not be needed at all. I think we could get rid of it and let the underlying framework (Vite, NextJs) take care of it.
We are open to contributions for this one.
I have similar problem with Next.js. Next.js use the same dotenv convention as Vite. Here's the documentation of it about Environment Variable Load Order
Hello @BatuhanW would love to work on this issue . Can you provide me little more context on what is needed to be done ?
Describe the bug
Vite uses dotenv (and a plugin or two) to load values from files with the following conventions:
Additionally, it behaves according to the following description:
(reference)
The Refine CLI automatically loads values in the
.env
file which appear to persist in the environment when executing the Vite commands (i.e.vite dev
).https://github.com/refinedev/refine/blob/16eefc493da3e66a095a11d9dcbeff0ec64dca57/packages/cli/src/utils/env/index.ts#L3
These take precedence and effectively break the
.env.local
,.env.development
, etc. conventions of Vite.CRA has slightly different but similar conventions. I assume the Refine CLI would be affecting it similarly?
Steps To Reproduce
.env
file with the contentVITE_TITLE=production
..env.development
file with the contentVITE_TITLE=development
.npm run refine dev
.import.meta.env.VITE_TITLE
is "production", not "development".Expected behavior
The Refine CLI shouldn't break Vite's dotenv conventions. In the trivial example provided, the value of
import.meta.env.VITE_TITLE
should be "development" from the.env.development
file.Packages
Additional Context
I explicitly renamed my
.env
file to.env.production
to "workaround" the issue. That file appears to not be loaded by the Refine CLI, and then my app builds as expected. It's an unfortunate workaround, effectively forcing us to not use the.env
file and "layering" of settings.