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

Concatenation not working #358

Open
apuatcfbd opened this issue Apr 6, 2023 · 3 comments
Open

Concatenation not working #358

apuatcfbd opened this issue Apr 6, 2023 · 3 comments

Comments

@apuatcfbd
Copy link

REACT_APP_URL_PROTOCOL=https
REACT_APP_URL=site.com

REACT_APP_BASE_URL="${REACT_APP_URL_PROTOCOL}://${REACT_APP_URL}"

This format was working with CRA but this is not working with env-cmd,

used like "build:test": "env-cmd -f .env.production.test react-app-rewired build"

Is there any way to make this work? Concatenation is important for my case

@pjetrucha
Copy link

@apuatcfbd
As a workaround, put a variable with concatenation (REACT_APP_BASE_URL) in env files that are default for CRA, such as:
https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used

@apuatcfbd
Copy link
Author

Thanks @pjetrucha but I didn't get it. I've different env's for different stages. in that scenario how do I do that?
I need this (for same env's vars): https://create-react-app.dev/docs/adding-custom-environment-variables/#expanding-environment-variables-in-env

@pjetrucha
Copy link

The CRA with env-cmd merges all the files together, so in your example, it will search for:

.env.production.test, .env.production.local, .env.local, .env.production, .env

The first file is from env-cmd, so variable expansion doesn't work in it, but you can move it to one of 4 other files that CRA will look for, e.g.:

# .env.production.test
REACT_APP_URL_PROTOCOL=https
REACT_APP_URL=site.com

# .env
REACT_APP_BASE_URL="${REACT_APP_URL_PROTOCOL}://${REACT_APP_URL}"

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

2 participants