First Heroku deploy failed `error code=H10` - node.js

I deployed my app to Heroku. It's a node.js + express + socket.io app and this is the package.json file
{
"name": "game_test",
"author": "Ilya",
"description": "A test app for our board game",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"express": "3.0.6",
"jade": "*",
"socket.io" : "*"
},
"engines": {
"node": "0.8.14"
}
}
This is the log I get:
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=game-test-1.herokuapp.com fwd=37.26.146.185 dyno= queue= wait= connect= service= status=503 bytes=
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=game-test-1.herokuapp.com fwd=37.26.146.185 dyno= queue= wait= connect= service= status=503 bytes=
What does it mean?

Found solution for me here: Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch)
In my case my app crashed because I was hard setting the PORT, instead of using the port that heroku dinamicaly sets, which can be accessed with process.env.PORT
app.listen(process.env.PORT || 3000, function(){
console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});

I just had a similar issue with my app, I got the issue after a migration of the DB, after trying many options, the one that helped me was this:
heroku restart
(Using Heroku toolbelt for mac)

I had this issue, the only problem was my Procfile was like this
web : node index.js
and I changed to
web:node index.js
the only problem was spaces

In my case, i found same error because there is version difference of node and npm on my local machine and defined in package.json version.
"engines": {
"node": "0.8",
"npm": "1.2.x"
}
when i check using
node --version : v0.10.41
npm --version : 1.4.29
when i update my package.json to
"engines": {
"node": "0.10.41",
"npm": "1.4.29"
}
It works fine :)

in my case adding process.env.PORT || 3000 to my http server script, resolved.
My heroku log reported 'H20' error and 503 http status.

In my case there was no start command in the script section of package.json file.
When I created the package.json file with npm init I did not create a start script command.
So I went to the package.json file, under scripts I added a new entry:
"scripts": {
"start": "node index.js"
},
Saved it and uploaded to Heroku and it worked

In my case, my Procfile was pointing to the wrong file (bot.js which I previously used) so once I updated it, the error was gone.

Also check your database connection. I forgot to change my database connection from localhost and this crashed my app once it was pushed to heroku.

I faced this same problem and none of the answers above helped me.
What i did was run:
node --version
and in the package.json add the engines section with your node version:
{
"name": "myapp",
"description": "a really cool app",
"version": "1.0.0",
"engines": {
"node": "6.11.1"
}
}

upon using hapi18, I find taking out the "host" field and setting the port to:
port: process.env.PORT || 5000 did the trick.

Old Thread, but I fix this issue by setting PORT constant to process.env.PORT ||
For some weird reason, it wanted to search Env first.

I had a typo
const PORT = process.env.PORT||'8080';
used to be
const PORT = process.env.port||'8080';

If you locally start node server by nodemon, like I did, and it locally works, try npm start. Nodemon was telling me no errors, but npm start told me a lot of them in a understandable way and then I could solve them by following another posts here. I hope it helps to someone.

In my own case, i got this error because i refuse to add a Procfile to my node js app and my "main": "app.js" was initially pointing to another js file as main. so doing these chnages get it fixed for me

Password contained a % broke it for me.

In my case, I forgot to set database env for deployment.
you can set env by this command
(I'm using mLab for MongoDB server)
heroku config:set MONGO_URI='mongodb://address'

For me it was Package.json it was empty from dependencies even though i thought i did install them.. so I had to reinstall them with --save option in the end and verify they were added to the package.json.. and then push it again and it worked.

My port was set to config.httpPort which resolves to 80. I fixed it by doing this:
const PORT = process.env.PORT || config.httpPort;
app.listen(PORT, ...)
Thanks a lot, it wasted me a lot of hours last night.

In my case I had code=H10 and status=503 because my
Procfile:
web: node build/server.js
and I included /build in .gitignore

My start command had env-cmd -f ./config/prod.env node index.js.
after changing to: node index.js it got fixed.

I got the same issue, the problem was my Profile was like this:
web: gunicorn__init__:app
Notice with the above there was no space between gunicorn and __ init __
instead of
web: gunicorn __init__:app

in my case the problem solved by changing the order :
From :
app.listen(2000 || process.env.PORT);
to :
app.listen(process.env.PORT || 2000);

Just got this error and resolved it. For anyone who has tried the other methods and failed, do check your Procfile path. My server was in the backend folder yet I only typed web: node server.js. I resolved the error after changing it to web: node backend/server.js

The H10 error code could mean many different things. In my case, the first time was because I didn't know that Heroku isn't compatible with Sqlite3, the second time was because I accidentally pushed an update with Google analytics working in development as well as production.

I got the same above error as "app crashed" and H10 error and the heroku app logs is not showing much info related to the error msg reasons. Then I restarted the dynos in heroku and then it showed the error saying additional curly brace in one of the index.js files in my setup. The issue got fixed once it is removed and redeployed the app on heroku.

Older thread, but for me I didn't set my .env vars in the Heroku console.

i was using body-Parser that throw exception
const bodyParser = require('body-Parser')
//Bodyparser Middleware
app.use(bodyparser.json())
intead of using
//Bodyparser Middleware
app.use(express.json())
this resolved my issue

I want to register here what was my solution for this error which was a simple file not updated to Github.
I have a full stack project, and my files are structured both root directory for backend and client for the frontend (I am using React.js). All came down to the fact that I was mistakenly pushing the client folder only to Github and all my changes which had an error (missing a comma in a object's instance in my index.js) was not updated in the backend side. Since this Heroku fetches all updates from Github Repository, I couldn't access my server and the error persisted. Then all I had to do was to commit and push to the root directory and update all the changes of the project and everything came back to work again.

I struggle with the same error for hours, but I was able to solve it. I installed multer and aws-sdk as a devDependencies by mistake, instead of just dependencies.
So, anyone who has the same error, just double-check your package.json file.
Also, a small tip for the property of the engine in package.json.
enter code here
//The greater or equal operators will make sure that you use the right node
//version
//even if your current node is greater version than npm node
"engines": {
"node": ">= 0.8.14"
},
//insted of
"engines": {
"node": "0.8.14"
}

I was deploying python Django framework when I got this error because I forget to put my app name web: gunicorn plaindjango.wsgi:application --log-file - instead of plaindjango

Related

Heroku H12 Request Timeout Error on Express route executing Python script

I'm running into this major issue on my Heroku app: I have an Express route set up
as follows:
app.get('/recommendations/:data', (req, res) => {
let dataSplit = req.params.data.split("");
let dataInt = [];
dataSplit.forEach(char => dataInt.push(parseInt(char)));
function sendPrediction(dataInf) {
const process = spawn('python', ["./predict.py", dataInt]);
process.stdout.on('data', (data) => {
let jSonned = JSON.stringify(data.toString('utf-8'));
let chopped = jSonned.slice(1, jSonned.length - 3);
res.send(chopped.split(','));
});
}
sendPrediction(dataInt);
});
When I make the GET request to this route from the frontend component, it times out with an H12 error after 30 seconds as per Heroku's default behavior. Since this route works fine on my localhost, it leads me to believe that there is something wrong with the Python dependencies, as I can replicate the same behavior on localhost by deactivating my virtualenv. I know this isn't much to go by, but if anyone has seen something like this and can help I'd greatly appreciate it.
How can I figure out where the issue is?
Here is the error from Heroku logs:
2018-04-30T17:17:27.175201+00:00 heroku[router]: at=error code=H12
desc="Request timeout" method=GET path="/recommendations/41231" host=what-
doxd.herokuapp.com request_id=2249d6ac-a389-40c1-8f64-8947796494a7
fwd="12.23.56.98" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0
protocol=https
Issue resolved: I needed to specify Python 2 and not let heroku default to python 3
First of all, you should attach your heroku logs to the question, so that we can see what Heroku is complaining about.
In absence of Heroku logs, I am guessing that you might not have a python buildpack defined for your app. Since your web dyno is built with node/express, you presumably already have a node.js buildpack (which Heroku may have added to your app automatically for you, if you didn't add it explicitly).
In that case, you need to add a python buildpack. Otherwise, python is not included in your app's slug.
See here for instructions on adding another buildpack to your app.

Heroku is giving me a 503 when trying to open my web app, works on local host

I am trying to deploy to heroku but get a 503 even though it runs on localhost. I am curious as to if my server is set up correctly as I am newer to programming. I hope anyone can point me in the correct direction as to where to look or provide a suggestion as I have spent countless hours on google to this point spanning a couple of weeks.
My main question is if I have set up my server correctly? I am not sure my listener will work for heroku and my .get are used for debugging on localhost when it was initially set up.
Also my full project is available here:
https://github.com/dirkdir/DerekDevSite
var express = require('express');
var app = express();
var path = require('path');
app.use(express.static(path.join(__dirname, 'public')));
app.get('/json', function(req, res) {
console.log("GET the json");
res
.status(200)
.json( {"jsonData" : true} );
});
app.get('/file', function(req, res) {
console.log("GET the file");
res
.status(200)
.sendFile(path.join(__dirname, 'app.js'));
});
var server = app.listen(process.env.PORT || 5000), function() {
var port = server.address().port;
console.log("Express is working on port " + port);
});
Logs:
2017-04-24T20:04:43.755866+00:00 app[web.1]: at Module._compile (module.js:542:28)
2017-04-24T20:04:43.755867+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10)
2017-04-24T20:04:43.755868+00:00 app[web.1]: at Module.load (module.js:487:32)
2017-04-24T20:04:43.755868+00:00 app[web.1]: at tryModuleLoad (module.js:446:12)
2017-04-24T20:04:43.755869+00:00 app[web.1]: at Function.Module._load (module.js:438:3)
2017-04-24T20:04:43.755869+00:00 app[web.1]: at Module.runMain (module.js:604:10)
2017-04-24T20:04:43.755870+00:00 app[web.1]: at run (bootstrap_node.js:393:7)
2017-04-24T20:04:43.755871+00:00 app[web.1]: at startup (bootstrap_node.js:150:9)
2017-04-24T20:04:43.846556+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-24T20:26:31.826133+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=derekdyerdev.herokuapp.com request_id=609ef253-0a56-41ac-b877-1fb242f6f4e1 fwd="69.36.89.218" dyno= connect= service= status=503 bytes= protocol=https
2017-04-24T20:26:32.319732+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=derekdyerdev.herokuapp.com request_id=f2a34e62-9765-
You have the bracket on line 34 of your app.js file in the wrong place.
Since the function is a callback, it needs to be within the params.
Change that last block to this:
const server = app.listen(process.env.PORT || 5000, () => {
const port = server.address().port;
console.log(`Express is working on port ${port}`);
});
I also modified the Procfile to just this:
web: node app.js
After I modified that I was able to run locally, and I deployed it to my Heroku just to test, and it works fine :)
This may be helpful to someone.
My initial Profile content was this :
web : node server.js
and after changing it to this, it worked :
web:node server.js
The space between 'web' and ':' symbol was the problem. Weird though
I had a similar issue. Worked on localhost.. not when deployed to Heroku. My problem? I had cloned a project (node_modules too) and my package.json did not have express, minimist etc.. so it obviously failed.
Tip: When deploying, view the logs right away so you can see what's happening throughout the deployment process. Viewing the logs after it has failed will only show you the end of the logs...
Lastly, ensure you listen on the proper port. I do this (as others do too)
var serverPort = 8080;
. . .
var port = process.env.PORT || serverPort;
I just had the same error on my heroku app.
I installed cors locally and pushed only the file app.js to the repository and deployed it to heroku.
The error was actually that the cors package wasnt declared on my package.json (I only pushed app.js to github) so when heroku tried to call the app it caused an error because cors was undefined.
The point is, also check if the package.json is updated.
This Might help others
From Terminal Check out your Heroku Logs
Check out the error message
This might be possible that any npm module you have installed globally
Then just install that npm module locally.
Commit the updated package.json and package-lock.json file on git.
Then run git push Heroku master.
I had to do a couple of things before I could get my app running, I will list all of them in case it helps anyone.
1.) Make sure you specify the version of node in your package.json file like this
"engines": {
"node": "14.15.1"
}
2.) Make sure you have no errors in your Procfile, the below command worked for me
web: node server.js
3.) My server.js file was inside the src folder and that was the root cause for me, I had
to move it out of that folder and then it started working for me
I was struggling with similar problem then noticed quotation marks in my Procfile. When I removed them problem solved.
"web: node index.js" WRONG!
It must be without quotes:
web: node index.js CORRECT!
I had this same issue when deploying a Rails 6 API only application to Heroku.
I was getting this error when I try accessing the application in a browser:
Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail
Here's how I fixed it:
I ran the command below to check the application logs:
heroku logs --tail
Then I scrolled up within the logs to view logs from when the application server was started. Then I found this error:
2020-12-17T12:28:46.973736+00:00 heroku[web.1]: Process exited with status 1
2020-12-17T12:28:47.017905+00:00 heroku[web.1]: State changed from starting to crashed
2020-12-17T12:28:47.028049+00:00 heroku[web.1]: State changed from crashed to starting
2020-12-17T12:28:50.252842+00:00 heroku[web.1]: Starting process with command `bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-production}`
2020-12-17T12:28:53.969375+00:00 app[web.1]: Puma starting in single mode...
2020-12-17T12:28:53.969443+00:00 app[web.1]: * Version 4.3.7 (ruby 2.6.6-p146), codename: Mysterious Traveller
2020-12-17T12:28:53.969472+00:00 app[web.1]: * Min threads: 5, max threads: 5
2020-12-17T12:28:53.969505+00:00 app[web.1]: * Environment: production
2020-12-17T12:28:57.565417+00:00 app[web.1]: ! Unable to load application: SyntaxError: /app/app/policies/user_policy.rb:4: duplicated argument name
2020-12-17T12:28:57.565428+00:00 app[web.1]: def initialize(user, user)
2020-12-17T12:28:57.565429+00:00 app[web.1]: ^~~~
2020-12-17T12:28:57.565468+00:00 app[web.1]: bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.6.0/bin/puma)
2020-12-17T12:28:57.565510+00:00 app[web.1]: SyntaxError: /app/app/policies/user_policy.rb:4: duplicated argument name
2020-12-17T12:28:57.565510+00:00 app[web.1]: def initialize(user, user)
2020-12-17T12:28:57.565511+00:00 app[web.1]: ^~~~
I fixed the error in my code which was caused by a duplicated argument name, that is def initialize(user, user) in my Pundit gem policies.
In the policies file for Users (app/policies/user_policy.rb) in my application, I simply renamed:
def initialize(user, user)
to
def initialize(user, user_model)
and almost did the renaming at the other places in the app/policies/user_policy.rb file that user, user was defined to user, user_model.
I saved and then pushed it to production and that fixed the issue for me.
That's all.
I have run app on local environment. In the log I saw "Module can not found 'index.js'" I updated my main js "app.js" to "index.js" and update package.json for main js. Then push my code to Heroku again. it worked.

How do I deploy an Angular.js app?

This may be a stupid question, but I'm wondering what platform I should use to deploy my Angular.js app? I tried using Heroku but got a "no Cedar-supported app detected" error. Any thoughts?
UPDATE
I'm trying to serve this to heorku as a Node.js application, but still can't seem to get it working. There's a web-server.js file in the root directory of my application and I reference it in my Procfile here:
web: node web-server.js
And here's my package.json file, also in the root directory:
{
"name": "medicare-data",
"version": "0.0.1",
"dependencies": {
},
"engines": {
"node": "0.10.x",
"npm": "1.2.x"
},
"respository": "medicare-data",
"author": "sararob"
}
I'm getting a "slug compilation error" in my heroku logs. Thoughts on why this might not be working?
You can run an Angular app on heroku if it is served as a node.js application. Usually, when you start working with Angular seed, there is already a node webserver script in the project. I believe if there is a package.json file in the root, heroku will detect and run it as a node.js application. I'll come back and update this answer with more detail shortly.
UPDATE
From the Heroku docs (and I am no expert), it has this passage after the deploy section: https://devcenter.heroku.com/articles/nodejs#visit-your-application
which basically tells you to make sure you have one dyno running. You can do that either through the web app under the settings of your app or you can run this:
$ heroku ps:scale web=1
To see if the process is running, do
$ heroku ps
=== web: `node web.js`
web.1: up for 10s
I bet if you look at your logs you'll see something like this:
2013-08-26T12:51:18.257006+00:00 heroku[web.1]: Starting process with command `node scripts/web-server.js`
2013-08-26T12:51:19.109974+00:00 app[web.1]: Http Server running at http://localhost:8000/
2013-08-26T12:51:34.369092+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path=/ host=cmwidget.herokuapp.com fwd="77.101.66.230" dyno= connect= service= status=503 bytes=
2013-08-26T12:52:19.445974+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
It means that your Angular seed app is using it's own port (8000), and Heroku doesn't allow this. You need to relinquish the assignment of the port number to Heroku.
Easily fixed. Modify scripts/web-server.js, and change this:
this.server.listen(port);
...to this:
this.server.listen(process.env.PORT || port);
I changed this line
var DEFAULT_PORT = 8000;
into:
var DEFAULT_PORT = process.env.PORT || 8000;
..and then it worked.
So I believe the reason is that heroku doesn't like your app running on port 8000.

Weinre on heroku

I am trying to set up Weinre on heroku but I am having some issues.
I manage to build the app, simply by using a package.json with weinre npm dependency and a Procfile that looks like the following
web: node_modules/weinre/weinre --httpPort $PORT
At first everything seems to work, the client shows up the UI, the JS file loads fine, but the debug does not work and no client ever shows up at the server side.
While looking at the logs, I realized that I keep getting 404 errors for every request that contains /ws/target/* or /ws/client/*
2012-05-31T22:37:53+00:00 heroku[router]: GET xxxx.herokuapp.com/target/target-script.js dyno=web.1 queue=0 wait=0ms service=10ms status=200 bytes=190900
2012-05-31T22:37:36+00:00 heroku[router]: GET xxxx.herokuapp.com/ws/target/t-3 dyno=web.1 queue=0 wait=0ms service=3ms status=404 bytes=9
2012-05-31T22:36:39+00:00 heroku[router]: POST xxxx.herokuapp.com/ws/client/c-1 dyno=web.1 queue=0 wait=0ms service=40ms status=404 bytes=9
This setup works localy with no problem.
I also tried the Procilfe with --boundHost 0.0.0.0 and got the same error. when I use my heroku app domain/subdomain as the host I got weinre: error running server: Error: listen EADDRNOTAVAIL error
If needed, you can checkout the source at the github repo
https://github.com/felipesabino/weinre-heroku
EDIT:
It is possible that it is related to WebSockets not being supported on Heroku:
https://devcenter.heroku.com/articles/http-routing#websockets
The weirdest thing is that the same issue happens with PhoneGap's weinre debug page as well
http://debug.phonegap.com/
Does anybody know how to solve this?
I have weinre running on Heroku at the moment but I remember that when I was trying to get it working it was a real nightmare.
This was using the 2.0.0-pre-H0WVARLU-incubating of weinre so it may be a bit different but what I had to do was:
Modify weinre itself, I had to tell weinre to bind to all hosts, I modified the cli.coffee file and I set the boundHost to -all- as the default
I commended out the if remoteAddress check in channelManager.coffee since the address you come in from is remapped through the proxy and was never matching
Turn on verbose debugging, while you don't actually need this to run it made it a lot easier to trace where errors are happening (and why the requests weren't routing)
My Procfile ended up being very simple as I tried to use weinre as "native" as possible (note the repo contains only weinre, it's not a module like you're doing):
web: node weinre
I left any port changes to be handled by process.env.PORT, not passed in from the Procfile
Basically what I found was that weinre really isn't designed to work behind a proxy!
See this pull request https://github.com/apache/incubator-cordova-weinre/pull/10
Note that no other modifications are needed, Procfile can set the options (like it should) and Weinre is properly used as node module.
package.json (that contains the fix)
"dependencies" : {
"weinre": "https://github.com/downloads/AppGyver/incubator-cordova-weinre/apache-cordova-weinre-2.0.0-pre-H77LBWIW-incubating-bin.tar.gz"
},
Procfile
web: node_modules/weinre/weinre --httpPort $PORT --boundHost -all- --debug true --verbose true
Modify weinre itself, I had to tell weinre to bind to all hosts, I modified the cli.coffee file and I set the boundHost to -all- as the default
I commended out the if remoteAddress check in channelManager.coffee since the address you come in from is remapped through the proxy and was never matching
this two Hints helped a lot on appfog, too
Also you need to
rename weinre to app.js
require local coffeescript
assign cli to a variable and execute run direct
extend cli.coffee - > Port with process.env.PORT

Heroku Error H14 (No web processes running)

Pretty sure some people encountered this problem before.
Followed all the instructions to setup node and npm. When pushing to heroku there were no errors. But when I open the app, it shows "Application Error"
heroku ps
returns
Process State Command
------- --------- ------------
main.1 up for 1m node main.js
while
heroku logs
returns
Error H14 (No web processes running) -> GET mewtwo.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=
I tried restarting the app with heroku restart but still get the same error. Google around and there were no other solution other than heroku restart. Anyone tried other methods ?
I had the same problem, but for me it was because I needed to run heroku ps:scale web=1
The name of your web process must be web, and this is the process that Heroku will always scale to '1' on initial deploy.
Other services in the Procfile can be called what you want, but you need to scale them initially (so you can have dev only processes in there if you want).
More information here: http://neilmiddleton.com/the-procfile-is-your-friend/
(the cached version: https://web.archive.org/web/20130926005616/http://www.neilmiddleton.com/the-procfile-is-your-friend)
I guess my problem was this, i had a python script in my node application which led heroku to believe that it is a python app, also i did not add a procfile since i expected the build bots to automatically detect that its a node app, so after setting up the procfile , then specifying the node and npm versions inside engines key in package.json, and changing the buildpack type to heroku/node, i got my app running.
Full disclosure, I solved this problem by turning it on.
Heroku Application Overview tab > click Configure Dyno > click the pencil icon > click toggle switch to On position > click confirm

Resources