Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand local variables not working. #122

Open
GeorgiosP opened this issue Feb 27, 2020 · 6 comments
Open

expand local variables not working. #122

GeorgiosP opened this issue Feb 27, 2020 · 6 comments

Comments

@GeorgiosP
Copy link

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"
   }
@toddbluhm
Copy link
Owner

toddbluhm commented Mar 3, 2020

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

@GeorgiosP
Copy link
Author

GeorgiosP commented Mar 4, 2020

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

@toddbluhm
Copy link
Owner

toddbluhm commented Mar 12, 2020

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 😄

@ryanfitzer
Copy link

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.

@nkrul
Copy link

nkrul commented Mar 10, 2021

Possibly fixed in: #253

@motdotla
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants