question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Building a React project in production loads the wrong environment variables

See original GitHub issue

Current 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

  1. Create a @nrwl/react app
  2. Create a .env file with some production variables inside
  3. Create a .local.env file with some development variables (with same key names as the one in the .env file inside
  4. Run nx build XXX and notice that only development variables are included - this IS the intended behavior
  5. 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
cereallarcenycommented, Feb 4, 2021

Could we at least reconsider opening this @jaysoo?

3reactions
unrealsolvercommented, Sep 12, 2022

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

create react app not picking up .env files? - Stack Overflow
In your project root you have to create two files with the same env variables but with different values: .env.development .env.production.
Read more >
React environment variables: A developer's guide - Architect.io
A hands-on guide for managing environment variables in your React app, including best practices and common mistakes.
Read more >
Managing .env variables for provisional builds with Create ...
Imagine that your project will have three separated provisional environments; development , staging , and production . Each environment is using ...
Read more >
Create-react-app environments - Medium
React imports environment variables that are defined in a .env file at the root of the project. Skip to Environment Configuration if you're...
Read more >
Environment variables in create-react-app - YouTube
GraphQL's strength lies in its flexibility and specificity. In a single query, you can ask for exactly what data you want.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found