"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.

1 Like

Hi Nazim,

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

1 Like

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.

1 Like

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.

1 Like

Hi @nazim.shoikot ,

Could you help me with the script you have written for the fix?

I am experiencing the same issue with PDFNet in react apps.

1 Like

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.

Thank you.

1 Like

Update here. We’ve dockerized our Lambda functions but still get this error even though yarn install is now installing the Linux version of the binary. What gives?

Hmm, sorry, not too sure.

Some possible hints:

  • Alpine-based images are not supported
  • We used serverless-webpack (but we have since moved away from serverless entirely)

We’ve been able to resolve this and ultimately Dockerized all our Lambda funcs using Serverless and that was the ticket to be able to use PDFNet and load some of their modules (like IDP).