-
Notifications
You must be signed in to change notification settings - Fork 653
Env vars are compiled into app #7
Comments
I vote yes. As the person who added the environment variables and a user of Heroku, I can tell you that this is the way I do it as well. If the environment variables change between environments, and these variables need to be embedded in the static app, then the app needs to be re-built for the environment. The other option may be to fetch the Heroku environment, and run For some reason I thought the script was |
Also something I have been considering lately is the pain of getting these environment variables into a CRA app in the first place. For example, I've been using the Pixie add-on which exposes a |
Great to hear from you @eliperelman
I'm proposing to make this change at the buildpack level, which would not required changes to apps such as individual developers making a Re: pain of non- heroku addons:create fixie --as REACT_APP_FIXIE See: Creating an add-on |
Wow, great info, thanks! |
Try the proposed stateless build strategy by using the buildpack branch: heroku buildpacks:set https://github.com/mars/create-react-app-buildpack.git#stateless-build Let me know how it goes 🍃 |
The biggest question remaining is: do folks have builds that take close to or longer than 60-seconds? |
Edit: release phase is not a solution, because changes to the slug filesystem are not persisted. |
I have a new solution which does not suffer from the same build-on-startup issue. Although, it does require adding some code to your React app. See: runtime-env-vars branch for the technique. Try it out by setting your buildpack to the branch: heroku buildpacks:set https://github.com/mars/create-react-app-buildpack.git#runtime-env-vars |
Updated with a new solution; see issue description. Planning to merge as the next version of create-react-app (0.7) is released. Feedback welcome! |
Resolved by #14 |
Updated Oct 16, 2016 with the final solution
Problem
When using the
REACT_APP_*
orNODE_*
environment vars to configure the React app, a rebuild (git push heroku master
) is required for changes to take effect. These values get embedded in the JavaScript bundle during build, whereas Heroku apps should always read config from environment variables.Examples of issues this causes:
Proposal
Perform replacement of environment variables in the bundle during the app start-up (via
.profile.d/
script), so that the current environment variables are used at runtime.Caveats
Try it
Try the proposed runtime env vars strategy by using the buildpack branch:
Then, follow the new Runtime vs Compile-time docs.
The text was updated successfully, but these errors were encountered: