throw new Error('Cannot create a client without an access token'); - node.js

I have almost deployed my app with heroku and when I try to add a campground in this case, it just gives me a blank thing. No error. This is what I get in my logs:
[[2021-10-15T20:53:49.474030+00:00 app[web.1]: (cloudinary secret)
2021-10-15T20:53:49.474721+00:00 app[web.1]: undefined
2021-10-15T20:53:50.059515+00:00 app[web.1]: /app/node_modules/#mapbox/mapbox-sdk/lib/classes/mapi-client.js:25
2021-10-15T20:53:50.059537+00:00 app[web.1]: throw new Error('Cannot create a client without an access token');
2021-10-15T20:53:50.059538+00:00 app[web.1]: ^
2021-10-15T20:53:50.059538+00:00 app[web.1]:
2021-10-15T20:53:50.059539+00:00 app[web.1]: Error: Cannot create a client without an access token]]
I have added all of my env variables. Checked them 3 times.

Related

Instagram Webhook Error, cannot load profile for <igsid>

I'm trying to get instagram messages with webhooks. I cloned the example "OC Coast Clothing IG" in github and upload on heroku.
However, when I test the webhook "messages" I get an error and my server crashes.
Here is my logs:
Could not load profile for 12334(this is the test id): Bad RequestTypeError: Cannot read properties of undefined (reading 'name')
2022-12-15T17:43:32.077647+00:00 app[web.1]: at Receive.handleTextMessage (/app/services/receive.js:78:45)
2022-12-15T17:43:32.077647+00:00 app[web.1]: at Receive.handleMessage (/app/services/receive.js:45:28)
2022-12-15T17:43:32.077649+00:00 app[web.1]: at /app/app.js:141:31
2022-12-15T17:43:32.077650+00:00 app[web.1]: at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2022-12-15T17:43:32.078205+00:00 app[web.1]: /app/services/receive.js:238
2022-12-15T17:43:32.078206+00:00 app[web.1]: id: this.user.igsid
2022-12-15T17:43:32.078206+00:00 app[web.1]: ^
2022-12-15T17:43:32.078207+00:00 app[web.1]:
2022-12-15T17:43:32.078207+00:00 app[web.1]: TypeError: Cannot read properties of undefined (reading 'igsid')
2022-12-15T17:43:32.078208+00:00 app[web.1]: at Receive.sendMessage (/app/services/receive.js:238:23)
2022-12-15T17:43:32.078208+00:00 app[web.1]: at Receive.handleMessage (/app/services/receive.js:71:12)
2022-12-15T17:43:32.078209+00:00 app[web.1]: at /app/app.js:141:31
2022-12-15T17:43:32.078209+00:00 app[web.1]: at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2022-12-15T17:43:32.078209+00:00 app[web.1]:
I have all the needed permissions, I can see the received webhook and the JSON data. I didn't change the example github code. Do I need to install some libraries in heroku terminal or what?

Selenium on heroku DevToolsActivePort file doesn't exist

So, I'm trying to deploy a node, selenium app to heroku.
This is how my code looks
let options = new Options();
options.setChromeBinaryPath(process.env.GOOGLE_CHROME_BIN);
options.addArguments("--headless");
options.addArguments("--start-maximized");
options.addArguments("--headless");
options.addArguments("--disable-dev-usage");
options.addArguments("--window-size=1920,1080");
options.addArguments("--ignore-certificate-errors");
options.addArguments("--allow-running-insecure-content");
options.setUserPreferences({"prefs":{"useAutomationExtension": false}});
let serviceBuilder = new ServiceBuilder();
console.log("initialized serice builder");
let driver = new Builder(process.env.CHROME_EXECUTABLE_PATH)
.forBrowser(Browser.CHROME)
.setChromeOptions(options)
.setChromeService(serviceBuilder)
.build();
This throws an error on the heroku logs like so
2021-05-18T05:42:15.372134+00:00 app[web.1]: /app/node_modules/selenium-webdriver/lib/error.js:517
2021-05-18T05:42:15.372174+00:00 app[web.1]: let err = new ctor(data.message)
2021-05-18T05:42:15.372175+00:00 app[web.1]: ^
2021-05-18T05:42:15.372176+00:00 app[web.1]:
2021-05-18T05:42:15.372176+00:00 app[web.1]: WebDriverError: unknown error: Chrome failed to start: crashed.
2021-05-18T05:42:15.372177+00:00 app[web.1]: (unknown error: DevToolsActivePort file doesn't exist)
2021-05-18T05:42:15.372180+00:00 app[web.1]: (The process started from chrome location /app/.apt/opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
2021-05-18T05:42:15.372181+00:00 app[web.1]: at Object.throwDecodedError (/app/node_modules/selenium-webdriver/lib/error.js:517:15)
2021-05-18T05:42:15.372181+00:00 app[web.1]: at parseHttpResponse (/app/node_modules/selenium-webdriver/lib/http.js:642:13)
2021-05-18T05:42:15.372181+00:00 app[web.1]: at Executor.execute (/app/node_modules/selenium-webdriver/lib/http.js:568:28)
2021-05-18T05:42:15.372182+00:00 app[web.1]: at processTicksAndRejections (node:internal/process/task_queues:96:5) {
2021-05-18T05:42:15.372182+00:00 app[web.1]: remoteStacktrace: '#0 0x5630d5f6be89 <unknown>\n'
2021-05-18T05:42:15.372183+00:00 app[web.1]: }
2021-05-18T05:42:15.465529+00:00 heroku[web.1]: Process exited with status 1
2021-05-18T05:42:15.532468+00:00 heroku[web.1]: State changed from up to crashed
Nothing seems to fix the issue, I've added the required buildpacks, and have also checked all the versions. Also note that this code runs perfectly fine on my local machine. I saw a similar question where the user manually added the DevToolsActivePort file, but that doesn't seem to be possible as I can't ssh into the heroku server.
Thanks in advance.
You will need to pass in a flag to disable Chrome Devtools Sandbox, so it will no longer look for DevToolsActivePort. It is also recommended to disable-gpu with a headless webdriver:
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-gpu");

TypeError: str.charAt is not a function at parse (/app/node_modules/pg-connection-string/index.js:13:11)

I have a node and express api deployed on Heroku and the api works fine for normal GET requests but when I try to Get or Post a request that involves querying a Postgre database from heroku add ons, such as registering a new user , it gives me error with this error log:
2020-09-13T18:48:39.984122+00:00 app[web.1]: TypeError: str.charAt is not a function
2020-09-13T18:48:39.984146+00:00 app[web.1]: at parse (/app/node_modules/pg-connection-string/index.js:13:11)
2020-09-13T18:48:39.984147+00:00 app[web.1]: at new ConnectionParameters (/app/node_modules/pg/lib/connection-parameters.js:56:42)
2020-09-13T18:48:39.984148+00:00 app[web.1]: at new Client (/app/node_modules/pg/lib/client.js:19:33)
2020-09-13T18:48:39.984148+00:00 app[web.1]: at BoundPool.newClient (/app/node_modules/pg-pool/index.js:201:20)
2020-09-13T18:48:39.984149+00:00 app[web.1]: at BoundPool.connect (/app/node_modules/pg-pool/index.js:195:10)
2020-09-13T18:48:39.984150+00:00 app[web.1]: at BoundPool.query (/app/node_modules/pg-pool/index.js:343:10)
2020-09-13T18:48:39.984150+00:00 app[web.1]: at /app/routes/UserAuth/jwtAuth.js:19:33
2020-09-13T18:48:39.984150+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2020-09-13T18:48:39.984151+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:137:13)
2020-09-13T18:48:39.984151+00:00 app[web.1]: at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
Two possibilities due to which you might be getting this error :
1.You are trying to access some other datatype as a string.
2.You are passing this as a callback, but str.charAt() returns a character and not function.
Check for both scenarios and since you have not shared code snippet, so could not suggest the exact code implemented solution.

Sequelize giving TypeError

So I was casually devoloping a simple node.js app and it was working in my computer just fine.
I had installed heroku toolbelt and the app was running fine when I ran foreman start.
Deploying the app in heroku seems to be giving me some kind of error when conecting with postgres by using sequelize (I'm not even 100% sure that's the cause of the error, but almost). The app crashes and all I have is the heroku logs:
2014-01-05T11:07:39.850661+00:00 app[web.1]: Servidor escuchando al puerto: 25144
2014-01-05T11:07:39.911641+00:00 app[web.1]:
2014-01-05T11:07:39.912039+00:00 app[web.1]: timers.js:103
2014-01-05T11:07:39.912288+00:00 app[web.1]: if (!process.listeners('uncaughtException').length) throw e;
2014-01-05T11:07:39.913123+00:00 app[web.1]: ^
2014-01-05T11:07:39.915970+00:00 app[web.1]: at TransactionManager.getConnectorManager (/app/node_modules/sequelize/lib/transaction-manager.js:25:36)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at TransactionManager.query (/app/node_modules/sequelize/lib/transaction-manager.js:39:15)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at module.exports.Sequelize.query (/app/node_modules/sequelize/lib/sequelize.js:310:36)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/sequelize/lib/query-interface.js:901:40)
2014-01-05T11:07:39.915970+00:00 app[web.1]: TypeError: Cannot call method 'setTypeParser' of undefined
2014-01-05T11:07:39.915970+00:00 app[web.1]: at new module.exports.ConnectorManager (/app/node_modules/sequelize/lib/dialects/postgres/connector-manager.js:19:19)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at module.exports.CustomEventEmitter.run (/app/node_modules/sequelize/lib/emitters/custom-event-emitter.js:24:18)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at Timer.list.ontimeout (timers.js:101:19)
2014-01-05T11:07:41.217303+00:00 heroku[web.1]: Process exited with status 1
2014-01-05T11:07:41.234281+00:00 heroku[web.1]: State changed from starting to crashed
The first line ("Servidor escuchando al puerto: XXXX") is actually part of app.js (the main .js file), it's the last few lines:
http.createServer(app).listen(app.get('port'), function(){
console.log('Servidor escuchando al puerto: ' + app.get('port'));
});
As I said before, it runs fine locally (executing foreman start correctly displays it on localhost) but I've had no luck on heroku.
Thanks for any insight and help =)
EDIT: I've managed to trace somewhat the error, seems there is a call to:
pg.types.setTypeParser(20, String)
somewhere in the sequelize module that throws the error since pg.types is undefined
I've checked by simply doing:
console.log(require('pg'));
And it indeed seems there is no field "types"
Is that the way it's meant to be? Am I missing something?
pg.types comes from a dependency of pg:
See package json here:
https://github.com/brianc/node-postgres/blob/master/package.json
This is the package here:
https://www.npmjs.org/package/pg-types
If you don't have it and you installed pg through npm, try removing pg and re-running npm install and see if there are any errors. It should download pg-types tool.
You can see where pg.types specifically is defined here:
https://github.com/brianc/node-postgres/blob/master/lib/index.js

Heroku Logs - open log referred to in error message

I'm deploying a node.js app to heroku (cedar stack)
I've set the NODE_ENV like this:
heroku config:add NODE_ENV=production
I then do:
git push heroku
However, after starting (i've got a console.log generating the first log entry) the app crashes.
I run:
heroku logs
and get the below error.
How can I open the /app/log/production.log that it's referring to?
app[web.1]: listening on port 32168 within production environment
app[web.1]:
app[web.1]: events.js:48
app[web.1]: throw arguments[1]; // Unhandled 'error' event
app[web.1]: ^
app[web.1]: Error: ENOENT, open '/app/log/production.log'
heroku[web.1]: Process exited with status 1
heroku[web.1]: State changed from starting to crashed
The error you're getting means that it's trying to open '/app/log/production.log' and is unable to do so. So find out where this logging is being attempted and disable or change it.
According to Heroku you should just be sending your application logs to STDOUT:
https://devcenter.heroku.com/articles/logging
So a console.log should be sufficient.

Resources