-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Enhancement: migrate from nan to node-addon-api (N-API) #1282
Comments
Hello, this is more a current limitation of native modules in Node rather than being a problem specific to sharp. Different versions of Node and Electron each have different ABIs, hence the need to ensure compilation occurred against the relevant runtime. Node provides a new ABI-stable N-API that aims to solve this problem. To take advantage of this we need to:
|
Understood. Thanks very much for the explanation @lovell. Is there no way to use different release directories for different binaries under the current system? I get that there's no good way, but I'd be okay with hacking things together in the meanwhile. Unfortunately I wouldn't have the slightest clue how to do it, if it can be done at all. It seems like some modules don't have this problem, gRPC for example. @murgatroid99, can you mention how gRPC approaches this? I know whatever gRPC and some other modules are doing works currently on |
For gRPC we distribute separate binaries for Node and Electron, and |
sharp uses prebuild to create separate binaries for Node and Electron. prebuild-install only downloads the relevant one at install-time and probably doesn't re-check at runtime, but it does have an install-time |
Thanks very much to you both for your insightful answers. |
@lovell Could anything be used as an alternative to prebuild? "Migrate sharp from nan to node-addon-api" - That sounds like something that can happen independently of waiting for other things to be ready (depending on developers' interest in doing so). Would there be a way to get Sharp to work on either node or electron without needing to be compiled differently? |
The prebuild changes have landed (although it looks like the linked issue hasn't been updated to reflect that) so that's no longer a problem. N-API is still marked as experimental in Node 6 but the use of |
I doubt I'll have time (or the right experience) to do this really soon. I've recently concluded that tensors provide a useful abstraction for image processing, and am going to focus on https://github.com/metabench/ta-tensor for the moment. I plan on making a C or C++ addon and also compiling to WASM for use in the browser. I'm interested in Sharp both because I've been using it, and to find out about best practises for making data-intensive addons. If it turns out that some new techniques I use would be useful to Sharp then I'd be in a better position to implement them in Sharp in the future. |
Based on my slightly painful experience in another module of migrating to N-API across various versions of Node 8, where different versions of Node, Electron and N-API all report the same ABI but don't even support the same API, upgrading to use N-API will have to wait until after we remove support for Node 8 at the end of 2019. |
An organisation that relies on sharp has very kindly offered to pay for the migration to N-API so expect to see some progress on this task over the next couple of weeks. |
The latest work-in-progress for N-API migration is now available for early/alpha testing on the https://github.com/lovell/sharp/tree/yield
npm install lovell/sharp#yield |
v0.25.0 now available with the use of N-API. I'm sure the maintainers of the many modules that depend upon sharp will be happy with the reduced level of installation issues this will bring. |
I'm trying to use this with
Electron
and run some tests inNode
but I absolutely cannot get a working version for each runtime working simultaneously. It always puts the built module intoRelease\sharp.node
, overwriting the previously built version.If I build for electron, I cannot test. If I build for Node, I cannot run it in Electron.
When I build for Electron, my tests return the following:
The file it says it cannot find does exist
When I build for Node, my app's renderer throws this error:
The text was updated successfully, but these errors were encountered: