Closed HasmH closed 2 months ago
Woops, sorry! I'm still new to ESM support in Node.js.
Despite my TS setup, which is surprisingly resilient to this error, I was able to write a test that fails based on your repro case: https://github.com/electrovir/pdf-text-reader/blob/c33bcfc4d698552bb064f233e3c5774292e106e6/src/esm-support.test.ts#L6
I've now fixed that test and deployed that fix in v5.0.1. Please try that version out!
Thanks very much. I ran into an issue with the new version of pdfjs-dist that I'll write here in case it helps someone.
pdfjs-dist v4 uses Promise.withResolvers, which is not supported by Node until version 22. AWS Lambda will not add Node 22 runtime until November 2024. To continue using this library on supported runtimes, we downgraded back to pdf-text-reader@4 and added a line into read-pdf.js:
async function readPdfPages({ data, filePath, password, pathToPdfJsDistNodeModule, progressCallback, url, }) {
const documentLoadingTask = (0, pdfjs_dist_1.getDocument)({
data,
isEvalSupported: false, <-- new line here
url: url || filePath,
useSystemFonts: true,
password,
standardFontDataUrl: pathToPdfJsDistNodeModule
? (0, path_1.join)(pathToPdfJsDistNodeModule, 'standard_fonts')
: undefined,
});
That workaround was suggested in the vulnerability report, so I believe everything is fine from a security perspective.
Thanks again for addressing this so quickly. We'll upgrade to v5 as soon as we can.
I ran into the same issue with Node versions. I can add an options input to readPdfPages
so you can pass in isEvalSupported
without modifying the source code.
Actually, looks like I already have that, but it's not being used, woops!
I'll fix here: https://github.com/electrovir/pdf-text-reader/issues/12
export * from './read-pdf.js';
(add a .js to the end of the import location)Documentation: https://nodejs.org/api/esm.html#mandatory-file-extensions
Originally posted by @AaronSterlingGENEICD in https://github.com/electrovir/pdf-text-reader/issues/10#issuecomment-2099444014
Using Node v22:
To reproduce: