Building a React project in production loads the wrong environment variables
See original GitHub issueCurrent Behavior
When building a @nrwl/react app in production mode (nx build XXX --prod
), the development environment variables (.local.env
) are loaded in addition to the production environment variables (.env
) and thus, the production variables are overwritten.
Expected Behavior
When building a @nrwl/react app in production mode (nx build XXX --prod
), I expect only the production variables to be included in the build.
Steps to Reproduce
- Create a @nrwl/react app
- Create a
.env
file with some production variables inside - Create a
.local.env
file with some development variables (with same key names as the one in the.env
file inside - Run
nx build XXX
and notice that only development variables are included - this IS the intended behavior - Run
nx build XXX --prod
and notice that only development variables are included - this is NOT the intended behavior
Environment
Node : 12.19.0 OS : darwin x64 yarn : 1.22.10
nx : Not Found @nrwl/angular : Not Found @nrwl/cli : 11.0.18 @nrwl/cypress : 11.0.18 @nrwl/devkit : 11.0.18 @nrwl/eslint-plugin-nx : 11.0.18 @nrwl/express : Not Found @nrwl/jest : 11.0.18 @nrwl/linter : 11.0.18 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : 11.0.18 @nrwl/react : 11.0.18 @nrwl/schematics : Not Found @nrwl/tao : 11.0.18 @nrwl/web : 11.0.18 @nrwl/workspace : 11.0.18 typescript : 4.0.5
I also have the NX CLI installed to version 11.0.18, but I don’t believe it was captured in the environment report above.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13 (3 by maintainers)
Could we at least reconsider opening this @jaysoo?
@jaysoo I would also ask to reopen that issue. I have both .env and .local.env. Sometimes I have to use manual deploys with e.g.
nx run app:deploy:production
. In this case I want to ignore.local.env
and use my.env
(or .env.production`) Currently, I have to remove .local.env and then restore it. It just makes no sense