Create-react-app: Question : Is it possible to run `npm start env.arbitrary`

Created on 19 Apr 2018  路  5Comments  路  Source: facebook/create-react-app

I have multiple env. variables set in different files (external services keys etc...), and I'd like to run the app in development mode with each environment variable easily... Something like

npm start env.demo
npm start env.staging
npm start env.production 
... etc 

Is it currently possible with the CRA setup?

Thank you 馃檹

documentation

Most helpful comment

You can use this same method for npm start:
https://github.com/facebook/create-react-app/blob/next/packages/react-scripts/template/README.md#customizing-environment-variables-for-arbitrary-build-environments

All 5 comments

You can use this same method for npm start:
https://github.com/facebook/create-react-app/blob/next/packages/react-scripts/template/README.md#customizing-environment-variables-for-arbitrary-build-environments

@Timer this is what I have :

"scripts": {
    "start": "react-scripts start",
    "start:prod": "env-cmd .env.production npm run start",
    "start:demo": "env-cmd .env.demo npm run start"
}

running npm run start:demo falls back to my .env variables and doesn't seem to use .env.demo

screen shot 2018-04-20 at 11 12 19 am 1

Any idea what could be going wrong? Thank you!

Hmm, that's very odd. What do your file contents look like? Can you try react-scripts start instead of npm run start?

I tried react-scripts start but still falls back to the .env file instead of .env.demo
All my .env files are in the root, and look like this :

MAILCHIMP_KEY = "KEY"
REACT_APP_API_URL = 'URL'
REACT_APP_ENV = 'demo'

& now package.json has this but still nothing :

"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build:demo": "env-cmd .env.demo react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"start:demo": "env-cmd .env.demo react-scripts start"
}

I suspect the format might be to blame.

Can you try just uh:

MAILCHIMP_KEY=KEY
REACT_APP_API_URL=URL
REACT_APP_ENV=demo

Also, make sure these variables aren't set in your shell already. Please open a new issue if you have a problem still!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JimmyLv picture JimmyLv  路  3Comments

alleroux picture alleroux  路  3Comments

stopachka picture stopachka  路  3Comments

Evan-GK picture Evan-GK  路  3Comments

ap13p picture ap13p  路  3Comments