toddbluhm / env-cmd

Setting environment variables from a file
https://www.npmjs.com/package/env-cmd
MIT License
1.73k stars 65 forks source link

env.production file is merged into the file claimed by -f option #335

Open zappyrent opened 2 years ago

zappyrent commented 2 years ago

I've 2 files in the root folder of the project: .env.staging and .env.production In the .env.production file there is a variable not present in .env.staging

When I run env-cmd -f ./.env.staging node index.js I can see the env variable present in the production file.

It looks like the final environment is calculated like that: {...env.staging, ...env.production}, merging .env.production into .env.staging

Is that correct?

namgold commented 2 years ago

Im facing this issue too

daichi-komatsu-asdf commented 2 years ago

Same issue in my react app. In my case, this was due to react-scripts.

Files on the left have more priority than files on the right:

  • npm start: .env.development.local, .env.local, .env.development, .env
  • npm run build: .env.production.local, .env.local, .env.production, .env
  • npm test: .env.test.local, .env.test, .env (note .env.local is missing) These variables will act as the defaults if the machine does not explicitly set them.

https://create-react-app.dev/docs/adding-custom-environment-variables