What is the Dockerfile to use node:12-alpine with puppeteer#1.19? - node.js

Since I faced puppeteer#1.13 error when printing pdf with lots of photos(at least need to renew the lock):
when running in Dev, there was exception:
(node:17) UnhandledPromiseRejectionWarning: Error: Page crashed!
at Page._onTargetCrashed (/usr/src/app/node_modules/puppeteer/lib/Page.js:176:24)
So I would like to use latest version of puppeteer#1.19. However, when I changed to use that, there is error :
Line239: await page.pdf({
path: TEMP_DIR + filename,
format: 'A4',
printBackground: true
});
printPdf() Error
Error: Protocol error (IO.read): Invalid parameters handle: string value expected
at /usr/src/app/node_modules/puppeteer/lib/Connection.js:183:56
at new Promise ()
at CDPSession.send (/usr/src/app/node_modules/puppeteer/lib/Connection.js:182:12)
at Function.readProtocolStream (/usr/src/app/node_modules/puppeteer/lib/helper.js:241:37)
at async Page.pdf (/usr/src/app/node_modules/puppeteer/lib/Page.js:988:12)
at async printPdf (/usr/src/app/puppeteer.js:239:9)
at async /usr/src/app/puppeteer.js:129:21
-- ASYNC --
at Page. (/usr/src/app/node_modules/puppeteer/lib/helper.js:111:15)
at printPdf (/usr/src/app/puppeteer.js:239:20)
at processTicksAndRejections (internal/process/task_queues.js:85:5)
at async /usr/src/app/puppeteer.js:129:21 {
message: 'Protocol error (IO.read): Invalid parameters handle: string value expected'
}
How can I prepare Dockerfile to support puppeteer#1.19 or solve this error? Thanks.

Related

MetaMask - RPC Error: execution reverted. Error: cannot estimate gas

I have a
MetaMask - RPC Error: execution reverted {code: -32000, message: 'execution reverted'}
next-dev.js?3515:25
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="execution reverted", method="estimateGas", transaction={"from":"0x563925491A8B3100c329d05292c059A84165dFB7","to":"0x159bB9B4A6b7f1165141Bc927a32237a143609C9","value":{"type":"BigNumber","hex":"0x016345785d8a0000"},"data":"0xd6febde800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001","accessList":null}, error={"code":-32000,"message":"execution reverted"}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.8)
at Logger.makeError (index.js?dd68:219:1)
at Logger.throwError (index.js?dd68:228:1)
at checkError (json-rpc-provider.js?8679:76:1)
at Web3Provider.eval (json-rpc-provider.js?8679:533:1)
at Generator.throw (<anonymous>)
at rejected (json-rpc-provider.js?8679:6:42)
I did everything by Clever Programmer's tutorial: https://www.youtube.com/watch?v=x3eRXeMB-4k&list=WL&ab_channel=CleverProgrammer. And now I have this error after running this piece of code:
const buyItem = async (
listingId = selectedMarketNft.id,
quantityDesired = 1,
module = marketPlaceModule
) => {
console.log(listingId, quantityDesired, module, 'david')
// yo RAZA lets goooo!!!
//yo Qazi, ok
// sure okay about to run it...
// just clicked buy now...
// still error
// where can i see the contract address of the marketplace module
// in [nftId.js]
await module
.buyoutDirectListing({listingId, quantityDesired})
.catch((error) => console.error(error))
confirmPurchase()
}

Shopify React Next Cannot read property "/_app" of undefined

I am trying to setup an environment to develop a shopify theme, and I followed the tutorial found here:
https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react/build-your-user-interface-with-polaris
But when I connected my server, the app, the store and so on, when I started integrating polaris, on build I started getting errors.
First I had an error about a missing module build-manifest.json and I found a suggestion somewhere on the forums to make a blank file with just {} in it in the .next/ directory and so I did.
Then it complained about react-loadable-manifest.json missing, and I did the same for it.
Both of these errors were being thrown from this piece of code:
server.use(async (ctx) => {
await handle(ctx.req, ctx.res); // <-- this line
ctx.respond = false;
ctx.res.statusCode = 200;
return;
});
And now I have the following errors:
error - ./node_modules/#shopify/polaris/dist/styles.css
TypeError: Cannot read property 'tapAsync' of undefined
TypeError: Cannot read property '/_app' of undefined
Thats the full stack, I dont see any "custom" code related to it:
error - ./node_modules/#shopify/polaris/dist/styles.css
TypeError: Cannot read property 'tapAsync' of undefined
TypeError: Cannot read property '/_app' of undefined
at getPageFiles (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\get-page-files.js:1:311)
at getDocumentFiles (C:\Users\Darkbound\Desktop\shopifyreact\server\.next\server\pages\_document.js:266:54)
at Head.render (C:\Users\Darkbound\Desktop\shopifyreact\server\.next\server\pages\_document.js:589:19)
at processChild (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:3450:18)
at resolve (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:3270:5)
at ReactDOMServerRenderer.render (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:3753:22)
at ReactDOMServerRenderer.read (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:3690:29)
at renderToStaticMarkup (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:4314:27)
at renderDocument (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\render.js:3:715)
at renderToHTML (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\render.js:56:103)
at async C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:107:97
at async C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:100:142
at async DevServer.renderToHTMLWithComponents (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:132:387)
at async DevServer.renderErrorToHTML (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:134:327)
at async DevServer.render (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:72:236)
at async Object.fn (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:56:580)
I came across this issue when jumping next multiple dependencies versions at once. I was able to resolve it by removing the wrapped Container
https://github.com/vercel/next.js/blob/master/errors/app-container-deprecated.md

pdf-merger-js throws a TypeError and Fails

I have been using pdf-merger-js to merge PDF files for a while now. I have used it with PDF files I have generated from HTML files and with PDF files I did not create.
Then I started getting the error:
Uncaught TypeError: Cannot read property 'compressed' of undefined
and the merger would fail. I tried different versions of node with the same results. The version that has been working is node v12.19.1.
/* /path/to/project/mpdf.js */
const PDFMerger = require('pdf-merger-js');
const path = require('path');
(async () => {
try {
const pdfs = ['pdf1.pdf','pdf2.pdf','pdf3.pdf','pdf4.pdf','pdf5.pdf'];
const merger = new PDFMerger();
pdfs.map(f => path.resolve(__dirname, "subfolder", f)
.forEach(pdf => merger.add(pdf));
//^^^Error occurs on this line
await merger.save('all-merged.pdf');
} catch( err ) {
console.log( err );
}
})();
Has any of you worked with pdf-merger-js and, have you encountered the above error? If so, how did you resolve the error?
Stack Trace
TypeError: Cannot read property 'compressed' of undefined
at parseObject (/path/to/project/node_modules/pdfjs/lib/object/reference.js:81:15)
at PDFReference.get [as object] (/path/to/project/node_modules/pdfjs/lib/object/reference.js:15:17)
at new ExternalDocument (/path/to/project/node_modules/pdfjs/lib/external.js:20:42)
at PDFMerger._addEntireDocument (/path/to/project/node_modules/pdf-merger-js/index.js:29:15)
at PDFMerger.add (/path/to/project/node_modules/pdf-merger-js/index.js:11:12)
at /path/to/project/app3.js:10:34
at Array.forEach (<anonymous>)
at /path/to/project/app3.js:10:12
at processTicksAndRejections (internal/process/task_queues.js:97:5)
Update
I have encountered another set of PDF files that are throwing a different error on the same line:
TypeError: Cannot read property 'object' of undefined
at new ExternalDocument (/path/to/project/node_modules/pdfjs/lib/external.js:20:42)
at PDFMerger._addEntireDocument (/path/to/project/node_modules/pdf-merger-js/index.js:29:15)
at PDFMerger.add (/path/to/project/node_modules/pdf-merger-js/index.js:11:12)
at /path/to/project/app3.js:10:34
at Array.forEach (<anonymous>)
at /path/to/project/app3.js:10:12
at processTicksAndRejections (internal/process/task_queues.js:97:5)
I got the same error whenever I used compressed PDFs for merging. Seems to be a bug in the underlying pdfjs library according to a Github issue in the pdf-merger-js repository.
Not the kind of answer I was looking for ....
If you flatten the files prior to merging them then the merging works fine. This seems to resolve the two errors I encountered.
I am using pdf-flatten just before merging as follows:
const fsp = require('fs').promises;
const flattener = require('pdf-flatten');
//....
const pdfs = ['pdf1.pdf','pdf2.pdf','pdf3.pdf','pdf4.pdf','pdf5.pdf'];
for(pdf of pdfs) {
const pdfB = await fsp.readFile(path.resolve(__dirname,"subfolder", pdf));
const pdfFlat = await flattener.flatten(pdfB, {density: 300});
await fsp.writeFile(path.resolve(__dirname,"subfolder", `flattened_${pdf}`), pdfFlat);
}
//....merge the flattened files:
//.... pdfs.map(p => `flattened_${p}`).....

Apollo server didn't print errors on node console

I have an Apollo server:
45 const server = new ApolloServer({
46 resolvers,
47 typeDefs,
48 debug: true,
49 })
On the client, I am getting an js error like:
extensions: {code: "INTERNAL_SERVER_ERROR",…}
locations: [{line: 3, column: 7}]
0: {line: 3, column: 7}
message: "Cannot read property 'split' of undefined"
but node console where the server is running didn't print anything:
node:63865) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
🚀 Server ready at http://localhost:4001/
Mongoose default connection open to mongodb://localhost/gepick
(node:63865) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
(node:63865) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead
According to the official doc: https://www.apollographql.com/docs/apollo-server/data/errors/#for-the-client-response
When initialize the ApoloServer, add the formatError: (err) => {...} property will print out the errors, see below:
const server = new ApolloServer({
typeDefs,
resolvers,
formatError: (err) => {
console.error(err);
return err;
},
});
Errors that occur during the resolution of a field are execution errors. Unless you catch the error yourself, it will be caught by GraphQL and returned as part of the response inside the errors array, as you are seeing. Because the error is caught, it will never show up in the console.
As long as the debug option is set to true and your NODE_ENV is development, the errors returned will include the stack trace inside the response as well. You've truncated the error in your post, but the stack trace should be found at the following path: errors[0]extensions.exception.stacktrace.
The returned error should also include a path property that should point to whichever resolver the issue is happening in.

Connection between node and MongoDB

I need help to solve this problem
After refactering the code to resolve the callback hell and use promises
I have that message in the terminal: (after NPM start)
(node:5312) DeprecationWarning: current URL string parser is
deprecated, and will be removed in a future version. To use the new
parser, pass option { useNewUrlParser: true } to MongoClient.connect.
Connected correctly to server
Insert Document:
[ { name: 'Vadonut',
description: 'Test',
_id: 5b9a880ac685ea14c035e05e } ]
Found Documents:
undefined
TypeError: Cannot read property 'result' of undefined
at dboper.insertDocument.then.then.then
(C:\Users\wael5\Desktop\coursera\node-mongo\index.js:29:59)
at
at process._tickCallback (internal/process/next_tick.js:188:7)
It would have been more useful if you could share your code, but your error seems simple enough.
1) You need to pass second arg as { useNewUrlParser: true } to MongoClient.connect()
2) At line node-mongo\index.js:29, you are trying to access result of undefined variable.

Resources