1

So I'm deploying a MERN stack app to heroku, and I have two .env files. One is for the nodejs backend, and one is for the react frontend. In heroku, you can set environment variables but they act essentially as a .env file in the root directory. However, my client folder is nested inside the node.js

2
  • 2
    Hi, please provide some code and error logs Commented Jul 9, 2020 at 21:54
  • Hi Mahesh Natamai, how did you solve this issue? I'm having exactly the same issue. Commented Nov 24, 2020 at 15:50

2 Answers 2

2

If you're using react-scripts, you just need to preface any React env variables with REACT_APP_. This is how it knows where they belong when it is building your app. So just add them to your code and to the config vars on Heroku as REACT_APP_NAME_OF_YOUR_ENV_VAR and you should be good.

Here's the docs from Create React App on how to do it using react-scripts and adding the env variables and here it is for Heroku

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the help, didn't know that heroku config variables get passed down to the react app.
Hi, how are you getting the Heroku env variables to be passed down? I can't get access to any in React which is in the client folder. The variables in Heroku are already prefixed with REACT_APP_ and have dotenv package in both root and client folder. Any help appreicated. Thanks
0

I missed to add the following line in the package.json script

"heroku-postbuild": "npm run build && DISABLE_ESLINT_PLUGIN=true npm run build --prefix web_client"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.