Pdfjs returning error that an ES5 build is required

Edit: It would seem that the error described below is due to the node incorrectly referencing the js library to be used. I am now having trouble doing a local deployment using "npm install c:\temp\node". The node will not show up in Node-Red

Original Problem Statement
I've got it in my mind that I'd like to try extracting text from a pdf when a trigger occurs. My basic workflow at the moment contains an inject node, a file input node, a pdf (node-red-contrib-pdfjs) node, and a debug node, connected in that order.

Node-red-contib-pdfjs seems to be the most recent version of the pdf reading nodes, and seems to have removed the necessity of having the now deprecated PhantomJS installed that other extensions required. This is a good thing, and hopefully also leaves the extension as processor type agnostic (I'm trying this on both x86 and ARM).

When I attempt to run the flwo with a known PDF file, I receive the following error in the debug node:

"UnknownErrorException: The browser/environment lacks native support for critical functionality used by the PDF.js library (e.g. ReadableStreamand/orPromise.allSettled); please use an ES5-compatible build instead."

That message seems to imply that pdfjs is expecting to be used in a browser, rather than within a workflow. My browser shouldn't be the issue, and certainly I'm expecting the process to be able to run without the user having a browser open looking at the flow.

Any suggestions would be very welcome. Googling the issue/error hasn't returned results that I seem to be able to do much with.

My flow:
[{"id":"35ee59ff.5051ea","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"726f33c3.30fdc4","type":"pdf","z":"35ee59ff.5051ea","name":"","filename":"C:\\temp\\AEIP Report Laidley.pdf","sortByY":false,"sortByX":false,"combineColumn":false,"combineRow":false,"x":550,"y":360,"wires":[["f6046883.a5ae08"],["f6046883.a5ae08"]]},{"id":"f6046883.a5ae08","type":"debug","z":"35ee59ff.5051ea","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":380,"wires":[]},{"id":"750368df.c588d8","type":"inject","z":"35ee59ff.5051ea","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":360,"wires":[["bd24f9d2.f63a58"]]},{"id":"bd24f9d2.f63a58","type":"file in","z":"35ee59ff.5051ea","name":"","filename":"C:\\temp\\AEIP Report.pdf","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":400,"y":260,"wires":[["726f33c3.30fdc4"]]}]

@redbackspider0

The message assumes that you are running in a browser, but with node-red it is running under nodejs which gives the pdf code a similar environment. The problem may be that you have too old a version of nodejs. What version are you running? Use
node -v
to find out. If possibly upgrade to version 14.x if you are at a lower version.

@colin I'm running v15 on a fresh/clean install on both the arm and win10 device.

I actually suspect that the issue is because the node specifies that pdf.js is used, but does not specify that the es5 version should be used. To remediate this I have downloaded the authors github repo, and tried to deploy locally using 'npm install c:\temp\repo'. Npm reports a successful install, but the node doesn't show in node-red. Doesnt show with the -g flag either.

The theory was that I could change the pdf.js json config file to point to the es5 version. If this worked I'd publish back the fork since the author of this version seems to have gone quiet.

It isn't recommended to use nodejs 15, you should stick the LTS version which is 14. I don't know whether that would help here, but I still suggest that you go back to 14 or you are likely to have some problems.

Did you happen to get this to work? I am trying to use the same node and would love a fixed version :slight_smile:

For anyone still looking its a simple fix from the code. in the pdf.js file change the first line from:
const pdfjsLib = require("pdfjs-dist/build/pdf.js");
to
const pdfjsLib = require("pdfjs-dist/es5/build/pdf.js");

I would make a change request on GIT but not sure how :slight_smile:

No time like the present to learn :wink:

This is the steps...

  1. Log in to github
  2. Open the repo main page
  3. Press the fork button
  4. Copy the URL from your fork
    image
  5. open a terminal on the computer and clone your repo git clone http://xxxxxxxxx
  6. edit the code, commit your changes git commit -m "fix ES5 issue #3"
  7. push your changes git push
  8. visit the original repo
  9. make a pull request
  10. wait for the dev to merge and push to npm

Phew, that took longer to write up than i thought.

Ok I think I did it. :grimacing: Thanks for the detailed instructions! There was one added step that it seemed I was suppose to do which was to do a git add pdf.js before the git commit, still pretty new to the whole thing. Thanks again!

2 Likes

Looks good.

I can see the reference to your PR in issue #3.

Might be worth adding a comment to the issue or your PR. If only to introduce yourself or link to this thread?

Good going with this one @mattjhughes @Steve-Mcl.

Matt, I tried your fix locally, but I can't seem to deploy the node and have it show up in node-red. If you have a working version perhaps you might consider publishing the node so it shows up in the pallette?

Thanks for posting the fix