Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Critical Error: cannot process multiple files at once #55

Closed
Zirafnik opened this issue Oct 11, 2024 · 3 comments
Closed

Critical Error: cannot process multiple files at once #55

Zirafnik opened this issue Oct 11, 2024 · 3 comments

Comments

@Zirafnik
Copy link

Zirafnik commented Oct 11, 2024

Because transforming PDFs into PNGs (and then further PNG processing) is computationally expensive I do it inside Node.js worker_threads, so they do not block the main thread execution.

When I try launching two threads, each processing its own PDF file the following error is thrown, which kills the thread process:

Error: Module did not self-register: '/home/user/backend/node_modules/canvas/build/Release/canvas.node'.
    at Object..node (node:internal/modules/cjs/loader:1586:18)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Function._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/home/user/backend/node_modules/canvas/lib/bindings.js:3:18)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Object..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Function._load (node:internal/modules/cjs/loader:1104:12)

Note: rm -r node_modules then npm install did not resolve the issue

Update: I found out that the issue lies with the canvas dependency, which still does not support worker_threads: Automattic/node-canvas#1394

@Zirafnik
Copy link
Author

@GreenFlag31 Yeah, I know. You should checkout the original "node-canvas" issue.

Also, your library adds no new functionality and is just a fork of this one?

@dichovsky
Copy link
Owner

Because transforming PDFs into PNGs (and then further PNG processing) is computationally expensive I do it inside Node.js worker_threads, so they do not block the main thread execution.

When I try launching two threads, each processing its own PDF file the following error is thrown, which kills the thread process:

Error: Module did not self-register: '/home/user/backend/node_modules/canvas/build/Release/canvas.node'.
    at Object..node (node:internal/modules/cjs/loader:1586:18)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Function._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/home/user/backend/node_modules/canvas/lib/bindings.js:3:18)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Object..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Function._load (node:internal/modules/cjs/loader:1104:12)

Note: rm -r node_modules then npm install did not resolve the issue

Update: I found out that the issue lies with the canvas dependency, which still does not support worker_threads: Automattic/node-canvas#1394

Currently "node-canvas" replaced with "@napi-rs/canvas". Please try v3.6.3

@Zirafnik
Copy link
Author

Hi, thanks for the update.

Replacing a key dependency feels scary, however, I trust you did extensive testing with the replacement. I only did a quick, surface-level research, but @napi-rs/canvas seems like a perfect drop-in replacement.

I found some worrying old issues, like missing support for some popular fonts, which I do not know if they are relevant to this library, or have perhaps even already been fixed.

I will upgrade and report back my findings, once I have more time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants