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

Add support for node native addons / napi / FFI in deno compile #23266

Open
marvinhagemeister opened this issue Apr 7, 2024 Discussed in #23255 · 7 comments
Open

Add support for node native addons / napi / FFI in deno compile #23266

marvinhagemeister opened this issue Apr 7, 2024 Discussed in #23255 · 7 comments
Labels
compile related to the `deno compile` feature feat new feature (which has been agreed to/accepted) node compat node native extension related to the node-api (.node)

Comments

@marvinhagemeister
Copy link
Contributor

marvinhagemeister commented Apr 7, 2024

Discussed in #23255

Originally posted by babakfp April 6, 2024
Hi 👋

parcel-bundler/lightningcss#712

Based on this comment parcel-bundler/lightningcss#712 (comment) and this:

Screenshot 2024-04-06 223807

(I used this library https://deno.land/x/abc@v1.3.3 and when I compiled, it started to download this ^ file).

It seems like Deno doesn't do the same for lightningcss.

Search keywords:

  • TypeError: LoadLibraryExW failed
@marvinhagemeister marvinhagemeister added bug Something isn't working correctly node compat labels Apr 7, 2024
@bartlomieju
Copy link
Member

I don't expect this to work. FFI/native Node extensions can't be included in the the compiled binary.

@lucacasonato lucacasonato added compile related to the `deno compile` feature node native extension related to the node-api (.node) feat new feature (which has been agreed to/accepted) and removed bug Something isn't working correctly labels Jun 11, 2024
@lucacasonato lucacasonato changed the title Error: Cannot find module '../lightningcss.win32-x64-msvc.node' Add support for node native addons / FFI in deno compile Jun 11, 2024
@AddictArts
Copy link

As a data point I ran into similar with electron-builder and now with deno. For elextron-builder I used asar.upacked which essentially put a node_modules and native within. Seems like deno should or maybe could do the same?

@Dmitri-Sintsov
Copy link

I don't expect this to work. FFI/native Node extensions can't be included in the the compiled binary.

Why not? These work with non-compiled source runtime. Anyway, in case these cannot be easily included, maybe the compiler could add these native modules as separate files to load them when running resulting binary? That would be much better than nothing.

@kt3k
Copy link
Member

kt3k commented Feb 10, 2025

I wonder if we can support loading native addons using --include flag of compile command. Did anyone try that?

@funnylookinhat
Copy link

funnylookinhat commented Feb 10, 2025

@kt3k I was wondering the same thing, but I think that would fail to properly support the --target parameter. I am pretty sure your local node_modules will be built only for your active architecture. As an example, if you were running on an M1 Mac and compiling for x86_64-unknown-linux-gnu, the binaries you include would not run properly in the resulting binary.

@sigmaSd
Copy link
Contributor

sigmaSd commented Feb 11, 2025

@kt3k it doesn't work it can't dlopen embedded files, the workaround is to copy the file to the host system before dl opening it

@sigmaSd
Copy link
Contributor

sigmaSd commented Feb 11, 2025

Bun for example does handle this pretty well, even complex napi projects like slint just works, bun compile produce a single executable that have the library bundled and it does dlopen it at runtime correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compile related to the `deno compile` feature feat new feature (which has been agreed to/accepted) node compat node native extension related to the node-api (.node)
Projects
None yet
Development

No branches or pull requests

8 participants