Reputation: 39
Today i moved my app from create react app to razzle for SSR but heroku fails to bind the PORT, I read other question but couldn't find a question like this I have set the PORT correctly but still can't bind it
"scripts": {
"dev": "razzle start",
"build": "razzle build",
"test": "razzle test --env=jsdom",
"start": "NODE_ENV=production node build/server.js",
"heroku-postbuild": "yarn build"
},
// const port = process.env.PORT || 4000;
export default express()
.use((req, res) => app.handle(req, res))
.listen(process.env.PORT || 4000, function(err) {
if (err) {
console.error(err);
return;
}
console.log(`> Started server`);
});
logs
2019-02-13T17:56:08.700969+00:00 app[web.1]: > NODE_ENV=production
node build/server.js
2019-02-13T17:56:08.700971+00:00 app[web.1]:
2019-02-13T17:56:10.910281+00:00 app[web.1]: > Started server
2019-02-13T17:56:12.000000+00:00 app[api]: Build succeeded
2019-02-13T17:57:05.112846+00:00 heroku[web.1]: State changed from starting to crashed
2019-02-13T17:57:05.119328+00:00 heroku[web.1]: State changed from crashed to starting
2019-02-13T17:57:04.991380+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2019-02-13T17:57:04.991503+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-02-13T17:57:05.096022+00:00 heroku[web.1]: Process exited with status 137
2019-02-13T17:57:18.472313+00:00 heroku[web.1]: Starting process with command `npm start`
2019-02-13T17:57:21.719632+00:00 app[web.1]:
2019-02-13T17:57:21.719660+00:00 app[web.1]: > *`enter code here`@2.0.1 start /app
2019-02-13T17:57:21.719662+00:00 app[web.1]: > NODE_ENV=production node build/server.js
2019-02-13T17:57:21.719663+00:00 app[web.1]:
2019-02-13T17:57:23.071400+00:00 app[web.1]: > Started server
2019-02-13T17:57:36.325346+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=*.herokuapp.com request_id=d322452e-de5a-479b-831a-a0345864671d
fwd="193.172.191.16" dyno= connect= service= status=503 bytes= protocol=https`
Upvotes: 2
Views: 276
Reputation: 39
Found out the issue,
I'm using RazzleJS
and during production It would inlines PORT environment or other environments that don't start with RAZZLE_
There were a few fixes but Razzle-heroku
was working great without changing any code.
Upvotes: 1
Reputation: 493
I faced the same problem and changing the port from
const app = express()
const port = 8000
app.listen(port)
to
.listen(process.env.PORT || 8000)
solved the issue for me
https://github.com/keystonejs/keystone/issues/3994#issuecomment-280639251
It basically says that removeing this from package.json might solve the issue"engines": {
"node": ">=0.10.22",
"npm": ">=1.3.14"
},
Upvotes: 1