-
Notifications
You must be signed in to change notification settings - Fork 377
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
Next JS ReferenceError: nodeUtil is not defined #303
Comments
Try adding this to your nextjs config: const nextConfig = {
experimental: {
serverComponentsExternalPackages: ['pdf2json'],
},
}; |
It's not the ideal solution, but it works for me. As a result, the library functions as expected, but the console output is not as nice as it was before. The mofified version can be found here: https://github.com/OferElfassi/pdf2jsonForElectron.git, |
@OferElfassi I came here with the same issue with Electron! Thanks for sharing your module. |
@OferElfassi your solution builds in Electron, but have you actually successfully run pdf2json from within Electron? I'm trying to run it from the main process and it just hangs, never firing const pdfData: PdfData = await new Promise<PdfData>((resolve, reject) => {
const pdfParser = new PDFParser();
pdfParser.on("pdfParser_dataError", (errData: unknown) => {
reject(errData);
});
pdfParser.on("pdfParser_dataReady", async (pdfData: PdfData) => {
resolve(pdfData);
});
pdfParser.loadPDF(localPdf);
}); The console output shows as follows: Load OK: C:\Users\david\Dropbox\DnD\Campaigns\Empire of the Chromatic Conclave\NPCs\zombie-minion.pdf
Warning: Setting up fake worker.
PDF loaded. pagesCount = 1
start to parse page:1
Skipped: tiny fill: 0 x 0 I can run the very same code in a stand-alone node process and it works just fine on the same PDF file with the following output: Load OK: C:\Users\david\Dropbox\DnD\Campaigns\Empire of the Chromatic Conclave\NPCs\zombie-minion.pdf
Warning: Setting up fake worker.
PDF loaded. pagesCount = 1
start to parse page:1
Skipped: tiny fill: 0 x 0
Success: Page 1
complete parsing page:1 Conspicuously absent fron the Electron debug output are the last two lines showing successful parsing of the page. So, running it from Electron, it's hanging somewhere in parsing the PDF. 😢 |
Hey @dprothero im glad my solution helped you. const extractFromPdf = (pdfPath):Promise<string[]> => {
return new Promise((resolve, reject) => {
const pdfParser = new PDFParser();
pdfParser.on('pdfParser_dataError', errData => {
console.error(errData)
reject(errData)
});
pdfParser.on('pdfParser_dataReady', pdfData => {
const processedData = [];
// ... code to extract text and other content from pdfData ...
resolve(processedData)
});
let dataBuffer = fs.readFileSync(pdfPath);
pdfParser.parseBuffer(dataBuffer);
})
} However, i still had some errors in production, so i ended up using the library as standalone module, outside package.json, you can find the modified version here: import PDFParser from "./pdf2json_standalone/pdfparser";
... rest of the code is the same as above. Hope this helps ☺ |
Now it throws the following error:
|
I am getting the same behavior on specific PDF files. @dprothero Did you fix it? I am also using the way @OferElfassi suggested, and it works but very rarely without just hanging. Perhaps it's because pdf2json updated their stuff and you need to update the standalone version? I would appreciate it if you took a look! |
@niemal I ran into the same issue... it would work with some PDFs and hang with others. I switched to pdf-parse-fork and it's been working great. |
Yeah turns out that's a memory leak and the whole thing is unusable in production. pdf-parse seems to work much more resiliently. |
@niemal how do you know it's a memory leak |
@darklight9811 were you able to fix this issue? |
please try v3.1.2 please |
Hi all,
While trying to parse pdf in NEXT JS throwing following error. Anyone have any idea regarding this.
The text was updated successfully, but these errors were encountered: