I'm deploying an Express app (Node.js/React) to Heroku and have set my env vars in Heroku using the config vars in Settings in the Heroku Dashboard. On the server side, I can access them using process.env
without any problems. However, in my client, my process.env
vars are returning undefined
.
I have prefixed them with REACT_APP
, and the issue seems to be related to the craco build
script in my client/package.json
that is called during the build stage of the Heroku deployment. If I set this to react-scripts build
, the environment variables behave as expected, however, my TailwindCSS config then fails.
I can also have a .env
file in the client, but I need different values depending on the stage of the Heroku pipeline, and NODE_ENV
is always "production"
once deployed to Heroku so I can't think of a way to have different values depending on the stage.
Is there a way for craco build
to get the REACT_APP
vars from the Heroku config vars during deployment in the same way react-scripts build
does?