env-cmd icon indicating copy to clipboard operation
env-cmd copied to clipboard

dotenv-expand support?

Open bhishp opened this issue 5 years ago • 5 comments

Is dotenv-expand supported? (https://github.com/motdotla/dotenv-expand)

I think not because I have attempted to add this to the env files but it doesn't work.REACT_APP_APP_VERSION=${npm_package_version}

(as per CRA docs:) https://create-react-app.dev/docs/adding-custom-environment-variables/#expanding-environment-variables-in-env

Happy to raise a PR to add support if someone could point me in the right direction...

bhishp avatar Oct 31 '19 17:10 bhishp

Currently dotenv-expand is not supported and probably will never be supported. But the idea of expanding existing env vars is a really cool idea. I will look into implementing that. If you would like to throw together a PR to get this feature implemented sooner, feel free to do so 😄

toddbluhm avatar Nov 01 '19 05:11 toddbluhm

@bhishp I had the same problem and I solved it by using dotenv-cli, which supports dotenv-expand.

You can use it as follows in you package.json:

"start": "dotenv -e .env.staging npm run develop",

eckertalex avatar May 14 '20 12:05 eckertalex

This is different from the existing --expand-envs correct? You have to send the vars in on the CLI or the env variable needs to already exist at run time iiuc?

It would be great to have REACT_APP_APP_VERSION=${npm_package_version} expand. If dotenv-cli can do it, we should be able to add the feature. Has the pr started for this?

Right now I am using an .env-cmdrc.json file with a .env file just for the version expansion. It's not ideal.

steveoh avatar Jan 28 '21 17:01 steveoh

I had a play - for simple expansions only, this should work: https://github.com/toddbluhm/env-cmd/pull/253

nkrul avatar Mar 10 '21 03:03 nkrul

you can use dotenvx for this

HELLO="World"
HELLO2=$HELLO
// index.js
console.log(`Hello ${process.env.HELLO}`)
console.log(`Hello ${process.env.HELLO2}`)
dotenvx run -- node index.js

motdotla avatar Feb 12 '24 05:02 motdotla