Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Issues
  • #4002
Closed
Open
Issue created Feb 09, 2018 by Administrator@rootContributor

Empty REACT_APP_ env vars in .env.production cannot override its counterpart in .env

Created by: MrOrz

Is this a bug report?

Yes.

When an REACT_APP_ environment variable is set in .env, we cannot overwrite it with an empty string.

In our scenario, our app tries to connect to an development API server running on local machine, but in production the static files built with npm build will be served directly with API server. The host name is set through an REACT_APP_ENDPOINT environment variable, with it being localhost in .env and being an empty string in .env.production. However, the empty string somehow cannot override the settings in .env.

In reality I worked-around this by putting REACT_APP_ENDPOINT in .env.development. Also, for API servers we can also use proxies instead. However, I think it's still a bit counter-intuitive that settings in .env.production cannot override the one in .env. That's why I opened this issue.

Did you try recovering your dependencies?

It's reproducible in fresh install of create-react-app

Which terms did you search for in User Guide?

  • env then read through "Adding Custom Environment Variables"

Environment

  1. node -v: v8.9.0
  2. npm -v: 5.5.1
  3. npm ls react-scripts (if you haven’t ejected): react-scripts@1.1.0

Then, specify:

  1. Operating system: Mac OSX

Steps to Reproduce

  1. Create .env and write REACT_APP_ENDPOINT=http://localhost:8080
  2. Create .env.production and write REACT_APP_ENDPOINT=
  3. inApp.js put:
console.log('ENDPOINT', REACT_APP_ENDPOINT} + '/api');
  1. npm run build
  2. Manually open the built main..js, search for 'ENDPOINT: '

Expected Behavior

Find this in the built js:

console.log('ENDPOINT', '/api');

Actual Behavior

Find this in the built js:

console.log('ENDPOINT', 'http://localhost:8080/api')

Reproducible Demo

Repo

https://github.com/MrOrz/create-react-app-env-override/

Relevant file

  • App.js
  • .env
  • .env
Assignee
Assign to
Time tracking