serverless-dotenv-plugin
serverless-dotenv-plugin copied to clipboard
Automatic env file resolution is in reverse order of precedence
The README says
The env resolution pattern follows the one used by Rail's dotenv and create-react-app
But the code says https://github.com/neverendingqs/serverless-dotenv-plugin/blob/6fc076c692c2947951966967041e24e10fb4df01/index.js#L64-L72 and https://github.com/neverendingqs/serverless-dotenv-plugin/blob/6fc076c692c2947951966967041e24e10fb4df01/index.js#L84-L91
That last .reduce() call means we're actually resolving the files in reverse order of precedence, since env vars in lower priority files are overwriting the ones in higher priority files.
The fix is potentially a breaking change, and so requires a major version bump.
When I implemented this, I used the create-react-app code as a sample. I now see this reduce may be causing issues.
https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/config/env.js
Is that why .env.local takes precedence over .env?
Is that why
.env.localtakes precedence over.env?
.local should always have higher priority then their non-local equivalents. This is by design to allow a single dev to override a shared env
Is that why
.env.localtakes precedence over.env?
.localshould always have higher priority then their non-local equivalents. This is by design to allow a single dev to override a shared env
I use this plugin in my local environment and when I deploy to the environments, however .env.local is replacing the values of my .env file that is generated at run time in the deploy pipeline, the correct one wouldn't be .env take priority over .env.local?
@feeh27 .env.local is intended to override .env. This is by design, not a bug.
You should not commit .env.local to your git repo. If you are running the deployment on an CI, it should not have access to .env.local at all.
If you are running the deployment locally, I suggest you use .env.development and .env.development.local when developing and then .env or .env.production when deploying. You can manage which file is read by using the --stage argument for serverless
I understood, really the way the library works and the projects I work on understand the .env.local and .env differently.
I have already managed to adjust this in my pipelines deleting the .env.local.
Thank you for your attention.
I'm still seeing .env values override .env.