Create-react-app: Unable to add custom environment variables

Created on 9 Nov 2016  路  3Comments  路  Source: facebook/create-react-app

NPM version: 3.10.9
[email protected]
node: 7.0.0

Description

Unable to add custom environment variables. Re: documentation

Expected behavior

  1. Create .env file with variables defined as:
FOO=bar
  1. Variables then made available to projects as:
process.env.FOO

Actual behavior

process.env.FOO is undefined.

Environment

MacOS 10.11.6
Chrome Version 54.0.2840.71 (64-bit)

Reproducible Demo

Demo

If there are additional usage steps, I suggest that they be explicitly called out in the create-react-app docs rather than linking to dot-env.

Most helpful comment

Hi @barcher , there is no additional steps. However, only env start with REACT_APP_ is available in the app, as noted in the section above your link https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables

All 3 comments

Hi @barcher , there is no additional steps. However, only env start with REACT_APP_ is available in the app, as noted in the section above your link https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables

Thanks @dvkndn! Perhaps as part of your documentation, you could discuss why you made the decision to prefix environment variables in this way? Closing.

@barcher just to be clear first, I'm not even here when we choose the 'REACT_APP' prefix, so I can't sure why.

Anyway, for me, it is really make sense to just add those which have 'REACT_APP_' prefix to our app. The advantages are similar with why you need to namespace your variables. For example, there are tons of things in process.env, and the prefix helps you avoid accidentally override one of them. Moreover, your env can also be used in multiple places rather than just in your react app, therefore it is good to make it clear which one is used in the react app.

Again, this is just my opinion 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oltsa picture oltsa  路  3Comments

onelson picture onelson  路  3Comments

alleroux picture alleroux  路  3Comments

fson picture fson  路  3Comments

callumlocke picture callumlocke  路  3Comments