Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError [ERR_INVALID_ARG_TYPE]: The "cb" argument must be of type function. Received undefined #309

Closed
brentreeves opened this issue Jul 26, 2023 · 4 comments

Comments

@brentreeves
Copy link

MAC OS M1 Ventura 13.4.1

npm run test is happy:
11 input files 11 success 0 fail 0 warning
pdf2json@3.0.4 [https://github.com/modesty/pdf2json]: 479.797ms

./pdf/va/form : Expected: NO Exception, All Parsed OK

It takes 8 seconds to process all PDFs ...

but the json example is not:

`╰─⠠⠵ node bnr_01.js
node:internal/validators:440
throw new ERR_INVALID_ARG_TYPE(name, 'Function', value);
^

TypeError [ERR_INVALID_ARG_TYPE]: The "cb" argument must be of type function. Received undefined
at maybeCallback (node:fs:177:3)
at Object.writeFile (node:fs:2272:14)
at PDFParser. (file:///Users/bnr01a/Documents/data/projects_current/pdf2json/bnr_01.js:8:8)
at PDFParser.emit (node:events:511:28)
at #onPDFJSParseDataReady (file:///Users/bnr01a/Documents/data/projects_current/pdf2json/node_modules/pdf2json/pdfparser.js:53:9)
at PDFJSClass. (file:///Users/bnr01a/Documents/data/projects_current/pdf2json/node_modules/pdf2json/pdfparser.js:69:77)
at PDFJSClass.emit (node:events:511:28)
at file:///Users/bnr01a/Documents/data/projects_current/pdf2json/node_modules/pdf2json/lib/pdf.js:221:38
at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v20.3.1

╭─~/Documents/data/projects_current/pdf2json on master✘✘✘ 23-07-26 10:43
╰─⠠⠵ cat bnr_01.js
import fs from "fs";
import PDFParser from "pdf2json";

const pdfParser = new PDFParser();

pdfParser.on("pdfParser_dataError", errData => console.error(errData.parserError) );
pdfParser.on("pdfParser_dataReady", pdfData => {
fs.writeFile("./test/bnr_01.json", JSON.stringify(pdfData));
});

pdfParser.loadPDF("./bnr_01.pdf")`

@Roxza
Copy link

Roxza commented Oct 14, 2023

"fs.writeFileSync("./test/bnr_01.json", JSON.stringify(pdfData));" you can edit the code in this way.

@alimustafa-poder
Copy link

This is an error in the docs of this library. fs.writeFile expects a callback and because you are not passing it, it throws an error. To fix this issue you need to define your above function like this:
fs.writeFile("./test/bnr_01.json", JSON.stringify(pdfData), (data) => { console.log(data)})
Replace your fs.writeFile line with the above and your code will work.

@abancp
Copy link

abancp commented Nov 29, 2023

this error coming when you forget a callback function .
eg
fs.unlink('./image.jpg') error
fs.unlink('./imgae',(err)=>{console.log(err)}) This is right way

mkrishnan-codes added a commit to mkrishnan-codes/pdf2json that referenced this issue Apr 16, 2024
documentation updated, from the comments - modesty#309 (comment)
modesty pushed a commit that referenced this issue Apr 16, 2024
documentation updated, from the comments - #309 (comment)
@modesty modesty closed this as completed Apr 16, 2024
@AJK-web
Copy link

AJK-web commented Sep 21, 2024

For my case , cb argument not define was just a comma "," mistake when i was declaring my arguments in the fs.writeFile() check if you accedently put a dot instead of a comma ","

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants