Puppeteer and nodejs throws error with Heroku - node.js

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!

Related

MERN deployment to Heroku

I'm having a really hard time figuring out how to deploy my app to heroku. Im new to all of this so I've tried different ways and following different tutorials but I just can't seem to find out how to do it.
This is my github repo:
https://github.com/solecity/card-deck-manager-app/tree/main
And in my logs from heroku I'm getting different errors:
2021-07-14T12:22:33.592361+00:00 app[web.1]: npm ERR! missing script: start
Starting process with command `node index.js`
2021-07-14T12:25:08.838023+00:00 app[web.1]: internal/modules/cjs/loader.js:905
2021-07-14T12:25:08.838048+00:00 app[web.1]: throw err;
2021-07-14T12:25:08.838048+00:00 app[web.1]: ^
2021-07-14T12:25:08.838049+00:00 app[web.1]:
2021-07-14T12:25:08.838049+00:00 app[web.1]: Error: Cannot find module '/app/index.js'
2021-07-14T12:27:16.812794+00:00 app[web.1]: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'express' imported from /app/server/index.js
If anyone could shed some light on how I can fix this it will be greatly appreciated
as the error states, you need to provide a start script in your package.json
apparently this is what heroku tries to runs. (error 1)
And if it doesn't find it, it runs something like node index.js (error 2)
also, you have not registered express in your dependencies in the main package.json so heroku doesn't install it. (error 3)
I'm not very used to heroku, but i think you should create 2 separate projects, and register them separately in heroku. that way he would find onlythe appropriate package.json and run.

Puppeteer discord bot keeps crashing when hosted on Heroku

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/.

Heroku Deployment succeed but not working

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

Log file (not found) / Heroku

While debugging an app on Heroku, I get this kind of message in the log console:
............
app[web.1]:
app[web.1]: npm ERR! A complete log of this run can be found in:
app[web.1]: npm ERR! /app/.npm/_logs/2017-08-19T03_00_34_428Z-debug.log
heroku[web.1]: Process exited with status 1
My problem is that I don't know how to find this file:
/app/.npm/_logs/2017-08-19T03_00_34_428Z-debug.log
The given path taken as is, is obviously wrong and wherever I look I do not see it.
Anyone knows where the file is?
I have the same question. Not able to find this log file.
However, you can view the log by setting it to verbose
heroku config:set NPM_CONFIG_LOGLEVEL=verbose
and then running git push heroku master

Heroku Node app keeps crashing

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.

Resources