'Heroku application crashed: at=error code=H10 desc=“App crashed” method=GET path=“/”
*I have been trying to upload my MERN app to Heroku and have been getting these error codes. The web application will run on my local host but the application immediately fails when I try and upload it to heroku. I am relatively new to working with the MERN stack and am trying to figure out how to properly upload an application to Heroku. *
2020-05-26T05:00:40.804369+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-fjord-39421.herokuapp.com request_id=9c5806e4-dd49-4325-8814-dccb9f4398e0 fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=https
2020-05-26T05:00:41.404224+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=murmuring-fjord-39421.herokuapp.com request_id=c325a3c6-b459-4de2-b7f5-fe67457f8d6e fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=httpsenter code here
2020-05-26T05:01:09.373344+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-fjord-39421.herokuapp.com request_id=4ad4f358-063e-48d7-a55e-7ccffc32ffb3 fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=httpsenter code here
heroku logs --tail
2020-05-26T04:54:22.910425+00:00 app[api]: Initial release by user [email protected]
2020-05-26T04:54:22.910425+00:00 app[api]: Release v1 created by user [email protected]
2020-05-26T04:54:23.096112+00:00 app[api]: Enable Logplex by user [email protected]
2020-05-26T04:54:23.096112+00:00 app[api]: Release v2 created by user [email protected]
2020-05-26T04:58:40.000000+00:00 app[api]: Build started by user [email protected]
2020-05-26T04:59:47.263635+00:00 app[api]: Deploy 7d333fc9 by user [email protected]
2020-05-26T04:59:47.263635+00:00 app[api]: Release v3 created by user [email protected]
2020-05-26T04:59:47.283454+00:00 app[api]: Scaled to web@1:Free by user [email protected]
2020-05-26T04:59:54.000000+00:00 app[api]: Build succeeded
2020-05-26T04:59:56.664155+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-26T04:59:59.487422+00:00 app[web.1]:
2020-05-26T04:59:59.487434+00:00 app[web.1]: > [email protected] start /app
2020-05-26T04:59:59.487434+00:00 app[web.1]: > react-scripts start
2020-05-26T04:59:59.487435+00:00 app[web.1]:
2020-05-26T05:00:02.028314+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.17.10.22/
2020-05-26T05:00:02.028881+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-05-26T05:00:02.029021+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-05-26T05:00:02.029167+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-05-26T05:00:02.029361+00:00 app[web.1]: Starting the development server...
2020-05-26T05:00:02.029362+00:00 app[web.1]:
2020-05-26T05:00:02.141290+00:00 heroku[web.1]: Process exited with status 0
2020-05-26T05:00:02.315545+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-26T05:00:02.318095+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-26T05:00:09.983236+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-26T05:00:12.651901+00:00 app[web.1]:
2020-05-26T05:00:12.651922+00:00 app[web.1]: > [email protected] start /app
2020-05-26T05:00:12.651923+00:00 app[web.1]: > react-scripts start
2020-05-26T05:00:12.651923+00:00 app[web.1]:
2020-05-26T05:00:16.868981+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.17.178.250/
2020-05-26T05:00:16.869628+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-05-26T05:00:16.869783+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-05-26T05:00:16.869929+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-05-26T05:00:16.870239+00:00 app[web.1]: Starting the development server...
2020-05-26T05:00:16.870241+00:00 app[web.1]:
2020-05-26T05:00:17.013391+00:00 heroku[web.1]: Process exited with status 0
2020-05-26T05:00:17.057205+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-26T05:00:40.804369+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-fjord-39421.herokuapp.com request_id=9c5806e4-dd49-4325-8814-dccb9f4398e0 fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=https
2020-05-26T05:00:41.404224+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=murmuring-fjord-39421.herokuapp.com request_id=c325a3c6-b459-4de2-b7f5-fe67457f8d6e fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=https
2020-05-26T05:01:09.373344+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-fjord-39421.herokuapp.com request_id=4ad4f358-063e-48d7-a55e-7ccffc32ffb3 fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=https
2020-05-26T05:11:05.245937+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-26T05:11:14.187854+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-26T05:11:16.938860+00:00 app[web.1]:
2020-05-26T05:11:16.938887+00:00 app[web.1]: > [email protected] start /app
2020-05-26T05:11:16.938887+00:00 app[web.1]: > react-scripts start
2020-05-26T05:11:16.938887+00:00 app[web.1]:
2020-05-26T05:11:18.963210+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.19.50.2/
2020-05-26T05:11:18.963807+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-05-26T05:11:18.963915+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-05-26T05:11:18.964030+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-05-26T05:11:18.964316+00:00 app[web.1]: Starting the development server...
2020-05-26T05:11:18.964319+00:00 app[web.1]:
2020-05-26T05:11:19.093706+00:00 heroku[web.1]: Process exited with status 0
2020-05-26T05:11:19.137119+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-26T05:11:19.140236+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-26T05:11:26.041885+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-26T05:11:28.043546+00:00 app[web.1]:
2020-05-26T05:11:28.043558+00:00 app[web.1]: > [email protected] start /app
2020-05-26T05:11:28.043558+00:00 app[web.1]: > react-scripts start
2020-05-26T05:11:28.043559+00:00 app[web.1]:
2020-05-26T05:11:29.727646+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.16.13.198/
2020-05-26T05:11:29.727983+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-05-26T05:11:29.728062+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-05-26T05:11:29.728128+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-05-26T05:11:29.728294+00:00 app[web.1]: Starting the development server...
2020-05-26T05:11:29.728295+00:00 app[web.1]:
2020-05-26T05:11:29.800107+00:00 heroku[web.1]: Process exited with status 0
2020-05-26T05:11:29.835462+00:00 heroku[web.1]: State changed from starting to crashed
server.js file
const bodyParser = require('body-parser');
const cors = require('cors');
const path = require('path')
const app = express();
require('./database');
app.use(bodyParser.json());
app.use(cors());
// API
const users = require('./api/users');
app.use('/api/users', users);
app.use(express.static(path.join(__dirname, '../build')))
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../build'))
})
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Server started on port ${port}`);
});
package.json file
{
"name": "my-project",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"bootstrap": "^4.5.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"mongoose": "^5.9.15",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "node backend/server.js",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install npm && run build",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:5000",
"engines": {
"node": "10.16.0"
}
}
Solution 1:[1]
For me, after checking everything else, the problem was in the empty path.
Don't deploy the API with an empty Path --> '/'
Allways give it a path like --> '/api/data'
The empty path makes the API think that favicon.ico is an ID you're trying to pass...
in my case For example i use:
app.use("/api/emps",require('./routes/employees.routes'))
Solution 2:[2]
This can be addressed in 2 ways :
1) This error is generally thrown if you forget to set a start script! Heroku demands a Procfile
(if you want to override the default start command of Heroku) to be uploaded along with your app files.
The content of Procfile
should be as such:
web: node index.js
(i.e specify the node command to be run for your application)
2) If you don't want to upload a Procfile then you can specify your command in the "scripts"
in package.json
(which you have already done), alongside you need to add "build":"webpack"
in package.json
.
You've also used "heroku-postbuild"
to replace the "build"
script......So actually it had to work! But you can try one of the above 2 methods and try to debug it (and hopefully one should definitely work)!
Solution 3:[3]
Add this to your server.js:
var distDir = __dirname + "/dist/";
app.use(express.static(distDir));
Solution 4:[4]
In React I did 2 things. One solved :)
- Added favicon and manifest using https://favicon.io/favicon-converter/
- Removed unused packages from
package.json
, you should also add development dependencies todevDependencies
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alejandro Orduz |
Solution 2 | Sagar Kulkarni |
Solution 3 | Tyler2P |
Solution 4 | Nagibaba |