agracio / edge-js

Run .NET and Node.js code in-process on Windows, macOS, and Linux
MIT License
632 stars 94 forks source link

Deno Support #222

Open HeyITGuyFixIt opened 2 hours ago

HeyITGuyFixIt commented 2 hours ago

I think it would great to have Deno supported in this project.

Deno is getting ready to release v2 very soon, which includes support for packages that use various install scripts. So testing with their rc and canary versions, I've been trying to get Edge.js working. When I install using deno install --allow-scripts --node-modules-dir=auto npm:edge-js@^22.7.0, it appears to successfully build, then Deno throws an error:

TypeError: LoadLibraryExW failed
    at Object.Module._extensions..node (node:module:797:20)
    at Module.load (node:module:665:32)
    at Function.Module._load (node:module:537:12)
    at Module.require (node:module:684:19)
    at require (node:module:808:16)
    at Object.<anonymous> (file:///C:/Users/Christian Sirolli/Documents/Projects/edgejsrepr/node_modules/.deno/edge-js@22.7.0/node_modules/edge-js/lib/edge.js:49:8)
    at Object.<anonymous> (file:///C:/Users/Christian Sirolli/Documents/Projects/edgejsrepr/node_modules/.deno/edge-js@22.7.0/node_modules/edge-js/lib/edge.js:177:4)
    at Module._compile (node:module:748:34)
    at Object.Module._extensions..js (node:module:767:10)
    at Module.load (node:module:665:32)

I'm not sure if this is something that Deno needs to fix, or is something you guys can help fix, or if I'm missing something. But at the moment, it is not working with Deno. In case it is a Deno issue, I opened a ticket with them here.

agracio commented 2 hours ago

From your output the call to edge-js is not coming from the correct path, you need to exclude it from packaging and rebuilding.

HeyITGuyFixIt commented 2 hours ago

There is a shortcut in node_modules called edge-js that points to "node_modules/.deno/edge-js@22.7.0/node_modules/edge-js". Not sure if that is what you are referring to.

agracio commented 2 hours ago

Thats exactly what I am referring to, you will not have a very good time using edge-js via shortcuts. edge-js needs full node_modules deploy from where its called.

HeyITGuyFixIt commented 2 hours ago

Doing a basic test with Node's REPL, and it imports edge-js without issue over the shortcut, and I could use it without issue. Not to say a more complex usage wouldn't run into an issue, but just that it shouldn't be the issue I am running into with Deno.

agracio commented 1 hour ago

Deno could be trying to load it differently TypeError: LoadLibraryExW failed is definitely a new one for edge-js. One thing that comes to mind is possible architecture mismatch.

HeyITGuyFixIt commented 1 hour ago

What can I do to try to figure out what library is failing to load?

agracio commented 1 hour ago

No idea tbh.

HeyITGuyFixIt commented 1 hour ago

When trying to install, after the error gets thrown, it says "Success: platform check for edge.js: node.js x64 v20.11.1". I guess Deno shows itself (in process.version) as Node v20.11.1. I am running x64 Windows 11 PC.

agracio commented 1 hour ago

Are you able to build a new experimental binary using tools/build.bat, there is something you could try. Clone edge-js repo, cd into tools and try running build release 20 in cmd. If you able to build new binaries I will provide some instruction that might help. If not I will try to provide experimental binaries using GitHub Actions.

HeyITGuyFixIt commented 59 minutes ago

My version of node (22) doesn't match up with deno, so running build release 20 fails. I'll tinker with it and see if I can get a build.bat script working with deno. Maybe that will help this work. I could also try to downgrade my node to 20.11.1 and see if that allows it to create a compatible version for deno.

agracio commented 57 minutes ago

build release 20 is not dependant on your Node.js version, are you able to access artefacts on Build actions https://github.com/agracio/edge-js/actions/runs/10964800678? Scroll all the way to the bottom of the run.

HeyITGuyFixIt commented 54 minutes ago

Yes I can access them

agracio commented 44 minutes ago

Once this build is done https://github.com/agracio/edge-js/actions/runs/11039818774 grab the artefacts and replace binaries in \lib\native\win32\ in your Dino project. This issue https://github.com/denoland/deno/issues/23465 mentions win_delay_load_hook setting.

agracio commented 30 minutes ago

Actually wait, need to run another build this has wrong settings. This build: https://github.com/agracio/edge-js/actions/runs/11040071911

nathanwhit commented 25 minutes ago

I believe the issue is that edge-js is a node addon that uses Node.JS and V8's APIs directly (e.g. https://nodejs.org/api/addons.html#c-addons) which are not ABI stable and deno does not support.

The addon would have to use exclusively napi (https://nodejs.org/api/n-api.html), which is ABI stable, for deno to support it. This would have the added benefit of being guaranteed to work across Node major versions with a single addon, instead of having separate addons for each node major version.


The LoadLibraryExW error occurs upon trying to load the addon because it has dependencies on dynamic libraries that are not present.

agracio commented 20 minutes ago

Well if that is the case then it does not look like edge-js is compatible with Dino.

HeyITGuyFixIt commented 9 minutes ago

@agracio Would it even be possible to switch to using the ABI stable API? It would definitely help with supporting more than just Deno, but other versions of Node as well. Not sure how big of a rewrite that would be, if possible.

agracio commented 6 minutes ago

Very unlikely edge-js has a very large C++ codebase that interfaces directly with V8 and nan unless someone is willing to take on that work and rewrite everything. To be honest it appears to be a niche issue that was never encountered before so the benefit would be very questionable.

There is also a big question of whether this is even possible.