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

Node.js Worker Thread compatibility #3

Open
thom4parisot opened this issue Apr 6, 2020 · 3 comments
Open

Node.js Worker Thread compatibility #3

thom4parisot opened this issue Apr 6, 2020 · 3 comments

Comments

@thom4parisot
Copy link

When I use Node.js Worker Thread to offload the work in another process, I encounter this error :

Error: Module did not self-register: '/path/to/app/node_modules/gdal-next/lib/binding/node-v72-darwin-x64/gdal.node'.
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1207:18)
    at Module.load (internal/modules/cjs/loader.js:1001:32)
    at Function.Module._load (internal/modules/cjs/loader.js:900:14)
    at Module.require (internal/modules/cjs/loader.js:1043:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/Users/oncletom/workspace/cartobio/front/node_modules/gdal-next/lib/gdal.js:26:31)
    at Module._compile (internal/modules/cjs/loader.js:1157:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1177:10)
    at Module.load (internal/modules/cjs/loader.js:1001:32)
    at Function.Module._load (internal/modules/cjs/loader.js:900:14)

The document specifies this:

Native add-ons can only be loaded from multiple threads if they fulfill certain conditions:

(…)

  • Be an N-API addon, or
  • Be declared as context-aware using NODE_MODULE_INIT() as described above.

There is a code example that makes a native module "context aware".

@yocontra
Copy link
Owner

yocontra commented Apr 6, 2020

@oncletom That's a great item for the roadmap - I do have on there to switch to N-API, but I will look into declaring it as a context-aware native module as an interim solution. I would also love to have this for our production cases.

@thom4parisot
Copy link
Author

Cool! Let me know if you need some testing — I kept my code while switching to worker-farm in the meantime.

I found Worker Thread integration easier (to write and debug) and less verbose to achieve identical result.

@yocontra
Copy link
Owner

yocontra commented Apr 6, 2020

If you have the time and want to try it out feel free to send a PR - I'm pretty busy this week and probably won't get around to this until next week.

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