Please give a brief summary of your issue:
During deployment, calls to PDFNet function returns error.
Please describe your issue and provide steps to reproduce it:
I have used PDFNet-node to edit a PDF document and everything works fine on my local machine (developed on Windows x64) but for testing, when I deploy it on a server (Linux x64), I first get an error named “Cannot find module ‘./addon’”. On refresh and subsequent request, I get the Error “Cannot read property ‘addEventListener’ of undefined”.
Edit: I found that the addEvent Listener part is because a messageHandler was also undefined. Upon replacing the undefined with empty objects and functions, I can see that the actual error is still that it could not find the module ‘./addon’;
After research, I am aware that the binaries for the two operating systems are different. I ran “npm install @pdfftron/pdfnet-node --target_arch=x64 --target_platform=linux” to get the PDFNetC.so file linux version of addon.node. I put these two files on the same directory as my index.js (the project is using webpack). I also tried multiple variations keeping both PDFNetC.dll and PDFNetC.so and using the corresponding addon.node file.
My current thought is to go into the pdfnet.js file, find the lines giving the error and disable them if they are not necessary but without the overall understanding, I think it can get quite messy and buggy. Hope you can provide me with some insight about why this occurs and how it could be solved.
If I should put some specific files somewhere, I would appreciate it if you could attach the link to them.
Hello, I tried this but it didn’t seem to work for me even with the correct binary.
I finally fixed the issue later. The problem was that webpack was converting the line “require(”./addon")" to a fixed import, which meant that it was not available during during packaging the index.js file for the server - it just showed a hardcoded error of “Module ‘./addon’ not found”. I wrote a script to change the fixed import to back to require, changed the addon.node to the correct node version, and put the binary files in the same folder as my index.js file - which seemed to have done the job.
We get the error “Cannot find module ‘./addon’” when using PDFNet Node SDK w/ Lambda. The problem is I am developing on MacOS and when I run yarn install, it installs the MacOS version of the SDK, but the Lambdas need to use Linux, I think.
@Ryan do you have any idea how to make this work for Lambda? Ideally I would yarn install the Linux version of the SDK locally even though my local environment is MacOS.