Puppeteer launch not working for no specific reason - node.js

Puppeteer launch not working for no specific reason. I'm completely confused because the same code works fine on basic node.js app. Even tho this is nest.js which i started learning this week, i'm still unable to find any workaround and solutions.
Tried with headless true & false and also with -> args: ['--no-sandbox', '--disable-setuid-sandbox'].
If anyone had similar experience, please tell. :/
code screenshot

You are importing it the wrong way.
Hence it gives you the type error,
Cannot read property "launch" of undefined
as puppeteer is undefined as you imported it in the wrong manner.
This should fix it,
import * as puppeteer from 'puppeteer';

Related

Vite and dealing with require vs import (for google api)

First time using Vite with google apis and right at the start ran into trouble trying to import the translation client. It uses 'require' to import it const {TranslationServiceClient} = require('#google-cloud/translate') instead of 'import' syntax. I've tried workarounds including the vite require plugin but nothing has worked (reworking it into an import statement causes different errors with 'process not defined' which just stumped me even more) and it seems strange that no one else seems to mention any problem with vite and google apis. Has anyone run into this issue?
Did you try?
import TranslationServiceClient from "#google-cloud/translate";

#google-cloud/pubsub TypeError: Cannot read property 'status' of undefined

Installed the google cloud pub sub following instructions from the following link,
https://cloud.google.com/pubsub/docs/reference/libraries
Imported that as the following,
const { PubSub } = require("#google-cloud/pubsub");
const projectId = "projectXYZ";
const pubSubClient = new PubSub({ projectId });
export async function publishMessage(topicName, data) {
return await pubSubClient.topic(topicName).publish(JSON.stringify(data));
}
this leads to the following error,
Now, what I have observed is that the code below the import has no significance in this issue, since this error still appears even if I only import on the first line.
Am I missing something or required to install something more that just the package?
Any help is deeply appreciated.
Thank you in advance.
Library maintainer here! I'm guessing from the stack trace that you're using webpack on your app? Right now we don't have webpack and rollup support - there are a few weird things like what you see above. Your code looks okay. We'd like to get webpack and similar tools working at some point for server-side usage, but it hasn't gone very high on the priority list just yet. I think the previous assumption was that people were trying to use it in a web browser, which we don't recommend for a number of reasons (most prominently, security concerns with GCP credentials). But I've been seeing a lot of issues with users trying to use webpack on the server side to make their Cloud Functions more compact, which seems pretty legit. I'll bring it up in our next team sync.
If you're not using webpack, then that sounds like something that might be filed over at the issue tracker.

PG (Node-Postgres) Pool Hangs on Connect ... But Only Inside Gatsby?

NOTE: This is mainly a question about the pg or Node-PostgreSQL module. It has details from Gatsby and Postgraphile, but I don't need expertise in all three, just pg.
I have a database that works great with a PostGraphile-using Express server. I can also acces it via node at the command line ...
const { Pool } = require("pg");
const pool = new Pool({ connectionString: myDbUrl });
pool.connect().then(() => console.log('connected'));
// logs 'connected' immediately
The exact same database also previously worked great with Gatsby/PostGraphile via the gatsby-source-pg plug-in ... but recently I changed dev machines, and when I try to build or run a dev server, Gatsby hangs on the "source and transform nodes" step. When I debug it, it's hanging on a call to pool.connect().
So I literally have two codebases both using PostGraphile, both with the same config, and one works and the other doesn't. Even stranger, if I edit the source code of the Gatsby plug-in in node_modules, to make it use the exact same code (which I can run at the command line successfully) ... it still hangs.
The only thing I can think of is that some other Gatsby plug-in is using up all the connections and not releasing them, but as far as I can tell (eg. by grep-ing through node_modules) no other plug-in even uses pg.
So really I have two questions:
A) Can anyone help me understand why connect would hang? Bonus points if you can help me understand why it would do so with a known-good config and only inside Gatsby (after some environmental factor changed)?
B) Can anyone help me fix it? If it might be some sort of "previous code forgot to release connections" issue, is there any way I can test for that? If I could just log new Pool().areYouBroken() somehow that would be amazingly useful.
Try:
npm install pg#latest
This is what got my pool/connection to start working as expected.
Annoying answer: because of a bug (thank you #charmander). For further details see: https://github.com/brianc/node-postgres/issues/2300
P.S. I never did find any sort of new Pool().areYouBroken() function.

I don't seem to be able to use ipcRenderer in electron

Using electron 8.0.3 (but the issue is also apparent with 8.1.0). The HTML page loads fine until I use ipcRenderer. Here is the Javascript code which I am including in the page:
const {ipcRenderer} = require('electron');
ipcRenderer.sendSync('testSync', 'sync ping');
When this is included I get the following error in the developer console in electron:
electron/js2c/renderer_init.js:1095 Uncaught Error: Unable to deserialize cloned data due to invalid or unsupported version.
at EventEmitter../lib/renderer/api/ipc-renderer.ts.ipcRenderer.sendSync (electron/js2c/renderer_init.js:1095)
at login.js:4
Any ideas? This is a freshly created project. I'm not even sure what the error is referring to with "invalid or unsupported version". I also get just a white screen in the electron window because the error is not caught, but even if I try to catch it, the process still dies.
The issue was JQuery. By adding the following code block from the electron docs, before JQuery was included, the problem was solved.
<script>
window.nodeRequire = require;
delete window.require;
delete window.exports;
delete window.module;
</script>
Funnily enough, I spent hours looking for a solution to this before posting this question. A solution then presented itself minutes later. Such is the life of the developer!

Struggling to take a React webpage screenshot

I want to take a screenshot of a React application webpage which opens at the following url when I run my application locally :
http://localhost:3400/someapi/email
I have unsuccessfully tried to take the screenshot with phantom (https://www.npmjs.com/package/phantom)
It failed because phantomJS has no support for ES6.
Also, I could not inject polyfill core.js (https://www.npmjs.com/package/core-js) to
the phantom js page with async await, as I am using Node v.6.9.1.
Any other alternatives/npm packages which makes this process of taking screenshot of a react webpage easy for me?
**Any detailed example would be much appreciated!

Resources