I am trying to setup a project for staging between dev to prod. I am trying to follow this article as it seems kind simple just to have a config file. https://serverless-stack.com/chapters/manage-environments-in-create-react-app.html
However early in the article he states you set the variable by doing this:
REACT_APP_TEST_VAR=123 npm start
When i start by app like that I get following: The term 'REACT_APP_STAGE=123' is not recognized as the name of a cmdlet, function. Any pointers?
you need to put the "REACT_APP_TEST_VAR=123" inside the script of npm start. For example when I run a npm build command it runs the following command (Where ENVIRONMENT is a env variable):
ENVIRONMENT=production webpack --mode production
So let's assume your cnpm start runs the regular "react-scripts start". You should define in your package json that the script "start" will do "REACT_APP_TEST_VAR=123 react-scripts start":
"start": "REACT_APP_TEST_VAR=123 react-scripts start",
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.