1

I'm trying to deploy a new React application to Heroku. I already did that without problems, but this afternoon I have this error:

enter image description here

The full error message is:

heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=XXXhiddenXXX.herokuapp.com request_id=199e3ff6-54c9-4711-bb1c-b6775dfe8799 fwd="92.148.12.118" dyno= connect= service= status=503 bytes= protocol=https

I tried a lot of solutions exposed here: Heroku deployment error H10 (App crashed)

Without success.

I restarted (several times) the dyno : without success.

My heroku-postbuild is:

npm install && npm install --only=dev --no-shrinkwrap && npm run build

Perhaps it is this script which generates this error?

halfer
  • 19,824
  • 17
  • 99
  • 186
Dom
  • 2,984
  • 3
  • 34
  • 64
  • Can you post the output from `heroku logs —tags`? – Joshua Rose Apr 25 '20 at 17:31
  • Check out this answer to a similar question https://stackoverflow.com/a/17004592/1680765. Also you may want to edit your previous comment to hide the sub domain. – Joshua Rose Apr 25 '20 at 18:04
  • Yes I read also this post. But did not understood it. What's this port ? I have a react app, without "back". I do not know where may I work ? add .env somewhere ? – Dom Apr 25 '20 at 18:16

3 Answers3

1

I find this solution :

I added a buidpack on my project. To do that :

  • go to your dashboard, tab 'Settings'
  • see the section 'buildpacks' :

enter image description here

Add the buildpack https://github.com/mars/create-react-app-buildpack.git

note : you can also add this build pack from your terminal :

heroku buildpacks:add https://github.com/mars/create-react-app-buildpack.git --app YOURAPP

Rebuild your application and that's all.

I must admit that I did not understand everything, but it is clear that it worked for me.

Dom
  • 2,984
  • 3
  • 34
  • 64
0

The default buildpack when deploying is that of node.js. You needed to use the create-react-app buildpack (as seen below).

heroku create $APP_NAME --buildpack mars/create-react-app
git push heroku master
heroku open
Bojan Mitrovic
  • 105
  • 1
  • 2
  • 10
0

You need to have the app running on a Heroku port using Express.

Step 1: Add server.js file to your project add add the following:

var express  = require('express');
var app      = express();                               
var morgan = require('morgan');            
var bodyParser = require('body-parser');    
var cors = require('cors');
 
app.use(morgan('dev'));                                        
app.use(bodyParser.urlencoded({'extended':'true'}));            
app.use(bodyParser.json());                                     
app.use(cors());
 
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header('Access-Control-Allow-Methods', 'DELETE, PUT');
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});
 
app.use(express.static('build'));
app.set('port', process.env.PORT || 5000);
app.listen(app.get('port'), function () {
  console.log('Express server listening on port ' + app.get('port'));
});

Step 2: Npm Install morgan, express and cors

Step 3: In package.json, change the "start" in scripts to "node server.js"

Step 4: Commit and Push to Heroku.

Step 5: Hard refresh your page.

You're welcome...

Chiaro
  • 1,447
  • 13
  • 13