Search code examples
environment-variablesyarnpkgreact-scripts

How do I pass arguments to react-scripts start command and use them in react?


I have a .sh file with the follow code:

react-scripts start HOST=0.0.0.0

And my yarn start scripts is:

"scripts": {
"start": "./run.sh",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"

},

The problem is that when I access to process.env object on a react component, I don't see this variable. How can I do this to work?


Solution

  • This seem to work for me: Setting environment variables in a shell script for a React app

    So the solution is to add REACT_APP as prefix of your variables.

    My .sh file ended like this:

    #!/bin/sh
    export REACT_APP_PYTHON_API_IP="localhost"
    yarn start