Bot works fine locally and even in the simlulated Heroku local heroku local web, but crashes after a minute or two when hosted on their servers online.
I have installed the buildpack for puppeteer:
https://github.com/jontewks/puppeteer-heroku-buildpack
I cleared my build cache:
https://help.heroku.com/18PI5RSY/how-do-i-clear-the-build-cache
I have tried to manually set my worker scaling to 1 heroku ps:scale web=1
This is my puppeteer browser launch arguments: {args: ["--no-sandbox", "--disable-setuid-sandbox"],}
List of my dependencies below:
discord.js
dotenv
node-fetch
puppeteer
fs
Logs are useless:
2020-05-15T11:40:56.804117+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-15T11:41:22.345051+00:00 app[web.1]:
2020-05-15T11:41:22.345073+00:00 app[web.1]: > discordbot#1.0.0 start /app
2020-05-15T11:41:22.345073+00:00 app[web.1]: > node bot.js
2020-05-15T11:41:22.345074+00:00 app[web.1]:
2020-05-15T11:42:20.278141+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-15T11:53:02.553013+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-15T11:53:25.758932+00:00 app[web.1]:
2020-05-15T11:53:25.758955+00:00 app[web.1]: > discordbot#1.0.0 start /app
2020-05-15T11:53:25.758956+00:00 app[web.1]: > node bot.js
2020-05-15T11:53:25.758956+00:00 app[web.1]:
2020-05-15T11:54:18.310840+00:00 heroku[web.1]: State changed from starting to crashed
I had a similar problem and applied this:
(Copied from Puppeteer Troubleshooting site. And It worked!)
Running Puppeteer on Heroku
Running Puppeteer on Heroku requires some additional dependencies that aren't included on the Linux box that Heroku spins up for you. To add the dependencies on deploy, add the Puppeteer Heroku buildpack to the list of buildpacks for your app under Settings > Buildpacks.
The url for the buildpack is https://github.com/jontewks/puppeteer-heroku-buildpack
Ensure that you're using '--no-sandbox' mode when launching Puppeteer. This can be done by passing it as an argument to your .launch() call: puppeteer.launch({ args: ['--no-sandbox'] });.
When you click add buildpack, simply paste that url into the input, and click save. On the next deploy, your app will also install the dependencies that Puppeteer needs to run.
If you need to render Chinese, Japanese, or Korean characters you may need to use a buildpack with additional font files like https://github.com/CoffeeAndCode/puppeteer-heroku-buildpack
There's also another simple guide from #timleland that includes a sample project: https://timleland.com/headless-chrome-on-heroku/.
Related
I created an app and ran it on my localhost which worked perfectly fine.
Then tried to deploy on Heroku, added Puppeteer Heroku and nodejs build pack.
Added the following args to the puppeteer launch function:
const browser = await puppeteer.launch({
headless: true,
args: ["--no-sandbox"],
});
also deployed with:
$ git add .
$ git commit -m "First commit"
$ git push heroku main
So far so good, no problems during deployment.
But when I open up the application, I just see that:
and get following errors in the logs:
2022-10-17T18:44:50.357107+00:00 heroku[web.1]: Starting process with command `npm start`
2022-10-17T18:44:52.117360+00:00 app[web.1]:
2022-10-17T18:44:52.117423+00:00 app[web.1]: > fetch-data#1.0.0 start
2022-10-17T18:44:52.117426+00:00 app[web.1]: > node server.js
2022-10-17T18:44:52.117429+00:00 app[web.1]:
2022-10-17T18:44:52.439078+00:00 app[web.1]: Listening on port 41022...
2022-10-17T18:44:52.441949+00:00 app[web.1]: /app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:69
2022-10-17T18:44:52.441949+00:00 app[web.1]: throw new Error(missingText);
2022-10-17T18:44:52.441949+00:00 app[web.1]: ^
2022-10-17T18:44:52.441950+00:00 app[web.1]:
2022-10-17T18:44:52.441951+00:00 app[web.1]: Error: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (1045629).
2022-10-17T18:44:52.441951+00:00 app[web.1]: at ChromeLauncher.launch (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:69:23)
2022-10-17T18:44:52.441951+00:00 app[web.1]: at async start (/app/bot.js:13:19)
As I can see he is trying to get to "/app/node_modules/puppeteer-core/.." which would be the wrong I assume?
Anyone who can help me out or prefer something else?
Thanks in advance!
I have a React app created with 'create-react-app' and setup for Heroku deployment with " heroku create --buildpack https://github.com/mars/create-react-app-buildpack.git." The initial deployment and the following ones via Travis CI were successful. However, since yesterday, while the app is still being deployed after successful build, it can not be opened and the Heroku log reads:
2018-10-09T20:14:16.000000+00:00 app[api]: Build succeeded
2018-10-09T20:14:19.093204+00:00 heroku[web.1]: Starting process with command bin/boot
2018-10-09T20:14:21.599174+00:00 app[web.1]: Injecting runtime env into /app/build/static/js/1.65a45b50.chunk.js (from .profile.d/inject_react_app_env.sh)
2018-10-09T20:14:22.010832+00:00 app[web.1]: Injecting runtime env into /app/build/static/js/main.b9301262.chunk.js (from .profile.d/inject_react_app_env.sh)
2018-10-09T20:14:22.212043+00:00 app[web.1]: Injecting runtime env into /app/build/static/js/runtime~main.229c360f.js (from .profile.d/inject_react_app_env.sh)
2018-10-09T20:14:22.748085+00:00 app[web.1]: Starting log redirection...
2018-10-09T20:14:22.748475+00:00 app[web.1]: Starting nginx...
2018-10-09T20:14:22.846806+00:00 app[web.1]: Process exited unexpectedly: nginx
2018-10-09T20:14:22.847047+00:00 app[web.1]: Going down, terminating child processes...
2018-10-09T20:14:22.845551+00:00 app[web.1]: nginx: [emerg] invalid number of arguments in "set" directive in ./config/nginx.conf:76
2018-10-09T20:14:22.949293+00:00 heroku[web.1]: State changed from starting to crashed
2018-10-09T20:14:22.950957+00:00 heroku[web.1]: State changed from crashed to starting
2018-10-09T20:14:22.935763+00:00 heroku[web.1]: Process exited with status 1
I can't see what the "set" directive refers to and how I am supposed to configure it. From my understanding the way to configure the Nginx server's behavior would be via the static.json file (https://github.com/heroku/heroku-buildpack-static#configuration) but I might be wrong. So far it is configured this way:
{
"root": "build/",
"routes": {
"/**": "index.html"
},
"proxies": {
"/api/": {
"origin": "${PORT}"
}
}
}
I also added an app.json as indicated here https://github.com/mars/create-react-app-buildpack#user-content-commit--deploy-%EF%B8%8F :
{
"buildpacks": [
{
"url": "mars/create-react-app"
}
]
}
The buildpack I am using configures the dyno this way so I shouldn't need a Procfile
I have done lots of research but can't find anything that could solve this issue. Any help is much appreciated!
Thank you!
I removed the proxies from my static.json file and it fixed the issue. The PORT I was referring to was unnecessary as I have already setup CORS on my backend.
My app works fine locally but when I build and move to live using heroku it just fails and following error shown in logs for the url https://polar-hamlet-97953.herokuapp.com/
2018-05-26T05:33:54.026228+00:00 app[web.1]: at /app/node_modules/sails/node_modules/async/lib/async.js:548:17
2018-05-26T05:33:54.026237+00:00 app[web.1]:
2018-05-26T05:33:54.030198+00:00 app[web.1]: Loading adapter (sails-mongo) from this app's node_modules/ directory...
2018-05-26T05:33:54.434024+00:00 app[web.1]: A hook (orm) failed to load!
Locally, it is in development mode and how to change it to production mode during deployment
I know it's maybe a beginner question, but I looked over it everywhere and I still having trouble with it.
I have a Node API that I run locally. The only thing I need to do is run in terminal:
$ mongod
and then
$ node src/loader.js
So, I upload my code to Heroku and added to my package.json:
"scripts": {
"start": "node src/loader.js"
}
But when I run '$ heroku ps' it says that my process crashed. Whats the difference between my local build and the Heroku build?
Adding my Heroku logs --tail.
2018-02-05T19:19:17.648257+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-02-05T19:19:17.648257+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-02-05T19:19:17.732544+00:00 heroku[web.1]: Process exited with status 137
Start by having a look over the heroku logs from terminal 'heroku logs --tail', and if you need more detail you can go to the app in heroku and in the upper right view the logs in the heroku platform.
If you can post some of the logs it will be helpful in telling what's going wrong if you can't derive it from there on your review.
So, I discovered the problem. Heroku dynamically assigns your app a port, so you can't set the port to a fixed number, and in my code I assigned to port: '3000'.
So you need to change to
var port = process.env.PORT || 3000;
I have an Express app hosted on Heroku. Locally it runs just fine, but keeps crashing on Heroku. Every time I go to it I get the 'Application Error' page.
I double checked all environment variables and they seem ok.
The Heroku logs don't exactly offer much help:
2017-04-16T23:02:49.001768+00:00 heroku[web.1]: State changed from crashed
to starting
2017-04-16T23:02:52.072906+00:00 heroku[web.1]: Starting process with
command `npm run start`
2017-04-16T23:02:56.042611+00:00 app[web.1]:
2017-04-16T23:02:56.042628+00:00 app[web.1]: > my-app#0.0.1 start /app
2017-04-16T23:02:56.042629+00:00 app[web.1]: > node bin/app
2017-04-16T23:02:56.042630+00:00 app[web.1]:
2017-04-16T23:02:57.200912+00:00 heroku[web.1]: State changed from starting
to crashed
2017-04-16T23:02:57.201454+00:00 heroku[web.1]: State changed from crashed
to starting
2017-04-16T23:02:57.192198+00:00 heroku[web.1]: Process exited with status 0
2017-04-16T23:03:00.981528+00:00 heroku[web.1]: Starting process with
command `npm run start`
2017-04-16T23:03:04.312475+00:00 app[web.1]:
2017-04-16T23:03:04.312489+00:00 app[web.1]: > my-app#0.0.1 start /app
2017-04-16T23:03:04.312490+00:00 app[web.1]: > node bin/app
2017-04-16T23:03:04.312491+00:00 app[web.1]:
2017-04-16T23:03:06.093211+00:00 heroku[web.1]: Process exited with status 0
2017-04-16T23:03:06.112842+00:00 heroku[web.1]: State changed from starting
to crashed
So then I tried starting the app manually:
$ heroku run bash
...
$ npm run start
I got no errors. I'm using the pm2 process manager, so I checked it to see if the app is running and it seems like it is:
$ node_modules/.bin/pm2 list
...
But then when I go to open my app I get the same 'Application error' page as before.
'heroku restart' doesn't help. It just crashes again every time.
The only difference between my local environment and Heroku (as far as I can tell at least...) is that locally I have a file from which I'm reading a RSA private key, and on Heroku that key is read from the environment.
Edit: As requested, here's my Procfile:
web: npm run start
Any ideas?
Your app need to start listening to the port defined in the env. For example if you have an expressjs app it should look something like this:
const express = require('express')
const app = express()
const port = process.env.PORT || 3000
app.get('/', (req, res) => res.send("Hello world"))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
If the app does not bind to the correct port, heroku is going to consider the app unhealthy and will terminate it.
You need to see this line in the logs, which indicates that heroku recognized the app as healthy:
State changed from starting to up
Keep in mind that this port thing is a special requirement for the web process. The other processes in your app does not have such a requirement.
Try 2 things:
Change your procfile:
web: node start.js
Then make sure that your web process it running by scaling it up:
heroku ps:scale web=1
On your computer in a terminal window run this command in your project:
heroku local web
It simulates how Heroku runs your app and should give you information of what is happening.