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

NodeJS native extensions can't access libraries APIs #2674

Open
nicolasnoble opened this issue Jul 21, 2018 · 8 comments
Open

NodeJS native extensions can't access libraries APIs #2674

nicolasnoble opened this issue Jul 21, 2018 · 8 comments
Labels
bug report Something is not working properly. help wanted Help is wanted in order to solve the issue. inactive No activity in a certiain period of time. nodejs Issue is about nodejs-related stuff, including npm.

Comments

@nicolasnoble
Copy link

I'm not sure if this one is even fixable, but the normal NodeJS runtime exposes libraries' API such as zlib or openssl to native addons. See https://nodejs.org/api/addons.html#addons_linking_to_node_js_own_dependencies

With termux's nodejs package, it seems this isn't working properly. See attached screenshot, when trying to load grpc (npm install grpc)

screenshot_20180721-013647

@fornwall fornwall added bug report Something is not working properly. help wanted Help is wanted in order to solve the issue. labels Aug 27, 2018
@fornwall
Copy link
Member

@nicolasnoble Thanks for reporting!

Could this issue explain the problem: android/ndk#201 or is it something else? Do you have any idea how to improve things (I don't know much about node.js internals myself)?

@nicolasnoble
Copy link
Author

It's very likely the case, yes. NodeJS is expecting its dependencies to be transitively available to its addons. If LD_PRELOAD is a way to put the dependents in the global space, we could wrap the Node binary to make sure that all of its dependencies are pre-loaded.

I'll give it a try.

@nicolasnoble
Copy link
Author

Yes, it's making it load using a wrapper script that LD_PRELOAD all the node libraries. I don't know yet if the module works properly, but that's outside the scope of this bug :-)

I'd recommend that the termux package ships with a similar script by renaming the binary to something else, and having the wrapper be the name "node", this way the node binary on Termux will behave the same as the official distribution.

image

@nicolasnoble
Copy link
Author

Also, the module seems to be working flawlessly, so only the wrapper script around the node binary is needed to properly fix this issue.

@stale
Copy link

stale bot commented Nov 18, 2021

This issue/PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix Issue won't be fixed. label Nov 18, 2021
@nicolasnoble
Copy link
Author

nicolasnoble commented Nov 18, 2021

¯\(ツ)

@stale stale bot removed the wontfix Issue won't be fixed. label Nov 18, 2021
@xtkoba
Copy link
Contributor

xtkoba commented Nov 27, 2021

The problem(?) is that there is more than one way to fix this.

I would rather do something like:

CXXFLAGS="-I$TERMUX_PREFIX/include" LDFLAGS="-L$TERMUX_PREFIX/lib -lz" npm install grpc

Of course the LD_PRELOAD hack will also work, as suggested above. And to patchelf the binaries is yet another.

@xtkoba xtkoba added nodejs Issue is about nodejs-related stuff, including npm. and removed not stale labels Dec 24, 2022
@stale stale bot added the inactive No activity in a certiain period of time. label Mar 11, 2023
@twaik
Copy link
Member

twaik commented Jan 20, 2024

Is this still reproducible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Something is not working properly. help wanted Help is wanted in order to solve the issue. inactive No activity in a certiain period of time. nodejs Issue is about nodejs-related stuff, including npm.
Projects
None yet
Development

No branches or pull requests

5 participants