Create react app provides no official way to inject environment variable from the server into the page.
When you run
yarn build create react app does bundle all the variables prefixed by
and expose them under
process.env (see here).
The problem, however, is that you likely don't want to build your app on the server.
You want to be able to do something like:
docker run --env FOO="xyz" org/my-app
and get access to
FOO in your TS/JS code like
The CRA team suggests to introduce placeholders in the
and do the substitution on the server before serving the app. This solution involves a lot of hard to maintain scripting.
react-envs abstract away the burden of managing environment variable injection as well as providing a type-safe way
to access them in your code.