env-cmd
env-cmd copied to clipboard
expand local variables not working.
running into an issue with expanding local variables inside an env file. working in v9.0.3 with this setup but seems to fail once I've moved over to a new CRA with env-cmd version 10.1.0
Request URL: http://localhost:5000/$REACT_APP_API_ENV_ORIGIN/
.env file:
REACT_APP_API_ENV_ORIGIN=someAPIURL.com
REACT_APP_API_ENV=$REACT_APP_API_ENV_ORIGIN
package.json:
"scripts": {
"build:integration": "env-cmd -f .env.integration craco build"
}
Wait are you saying that expanding local variables inside of a .env file worked in v9.0.3?
I honestly do not remember ever implementing that feature. It has been requested before, but I have not gotten around to implementing it yet. Someday soon hopefully!
Currently, env expansion only works for arguments passed on the command line.
This is sort of a duplicate of #97
I might be using the wrong term here but let me expand on my example with the above snippet. it might be up the chain and not related to env-cmd but I'm not 100% sure on that. I'll need to do some more research.
The fix i've done for now is just assigning the url directly instead of referencing it within my env file.
call the following env var inside my react app in v9.0.3 with craco and node version v10.15.3
process.env.REACT_APP_API_ENV/slug
network requests will map to
someAPIURL.com/slug
same code with v10.1.0 within a react app and craco on node v10.15.3
maps to the following and fails
$REACT_APP_API_ENV_ORIGIN/slug
Interesting...could you create a small functioning repo project demonstrating this issue that I can use to test with? I know it is a bit more work, but it would really help!
Together, hopefully we can get this issue resolved 😄
This would be a great feature.
@GeorgiosP Just tried this on v9.0.3 and the var was not expanded, so it may be up the tool chain somewhere. Not sure about CRA, but Next.js does this out-of-the-box.
Possibly fixed in: https://github.com/toddbluhm/env-cmd/pull/253
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