1
votes

I have a problem when I am making a production build on my create-react-app project and deploying it to Heroku. On Heroku it still uses the development mode. I have changed the NODE_ENV to production on Heroku, but still, it does not want to set it on my project.

2
heroku config:get NODE_ENV definitely returns "production"? - Dominic

2 Answers

1
votes

This happens because Heroku serves src directory of your project. This is my scripts settings to serve build folder.

"scripts": {
  "dev": "react-scripts start",
  "start": "serve -s build",
  "build": "react-scripts build",
  "test": "react-scripts test",
  "eject": "react-scripts eject",
  "heroku-postbuild": "npm run build"

}

1
votes

Couldn't get @Varo Manukyan's answer to work. I came up with the following:

First, set the production variable in the heroku cli:

heroku config:set NODE_ENV=production

Then, just change your package.json scripts to and you are good to go:

 "scripts": {
       "heroku-prebuild": "npm install -g serve",
       "devstart": "react-scripts start",
       "start": "serve -s build",
       "build": "react-scripts build",
       "eject": "react-scripts eject",
 },

With "heroku-prebuild" you can install the serve wihtout having to upload any additional code.