"Cannot find module './addon'" error during deployment

Product: PDFNet-node

Product Version: 9.2.0-1

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.

Thank you in advance.

Hi Nazim,

Please take a look at the following forum post for more information:

We are also experiencing this issue with webpack.

Have forced reinstall of node modules, rebuilt the pdftron module (npm rebuild @pdftron/pdfnet-node), etc. Nothing seems to resolve this around playing with pulling in the dependency differently.

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.